{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "another-government",
   "metadata": {},
   "source": [
    "# 一、载入配置文件，载入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "renewable-muscle",
   "metadata": {},
   "outputs": [],
   "source": [
    "import configparser\n",
    "import os\n",
    "import json\n",
    "\n",
    "import pandas as pd\n",
    "class ConfigFile:\n",
    "    def __init__(self, path):\n",
    "        self.path = path\n",
    "\n",
    "    def ReadConfig(self):\n",
    "        # 判断是选择使用哪个模型\n",
    "        '''\n",
    "        主要有4种不同的配置文件\n",
    "        1、半监督学习配置文件\n",
    "        2.1、无监督学习配置文件（节点为文件）\n",
    "        2.2、无监督学习配置文件（节点为文件）NodeGCN模型\n",
    "        2.3、无监督学习配置文件（节点为符号）\n",
    "        Returns:\n",
    "        {配置a：配置值a,}\n",
    "        '''\n",
    "\n",
    "        cf = configparser.ConfigParser()\n",
    "        cf.read(self.path)  # 读取配置文件，如果写文件的绝对路径，就可以不用os模块\n",
    "        if cf.has_option(\"Model\", \"type\"):\n",
    "            train_type = cf.get(\"Model\", \"type\")\n",
    "            if train_type.startswith(\"un\"):\n",
    "                return self.Read_unSurpervised_Config()\n",
    "            else:\n",
    "                return self.Read_semi_Surpervised_Config()\n",
    "\n",
    "    # 读取半监督学习的配置文件\n",
    "    def Read_semi_Surpervised_Config(self):\n",
    "        cf = configparser.ConfigParser()\n",
    "        cf.read(self.path)  # 读取配置文件，如果写文件的绝对路径，就可以不用os模块\n",
    "        kwarg = {}\n",
    "\n",
    "        # 数据存储的位置\n",
    "        if cf.has_option(\"Data\", \"path\"):\n",
    "            kwarg['root'] = cf.get(\"Data\", \"path\")\n",
    "\n",
    "        # 数据存储的类别\n",
    "        if cf.has_option(\"Data\", \"project\"):\n",
    "            kwarg['project'] = cf.get(\"Data\", \"project\")\n",
    "\n",
    "        # 判断是选择使用哪个模型\n",
    "        if cf.has_option(\"Model\", \"name\"):\n",
    "            kwarg['model_name'] = cf.get(\"Model\", \"name\")\n",
    "\n",
    "        # 判断模型的类别是半监督还是无监督\n",
    "        if cf.has_option(\"Model\", \"type\"):\n",
    "            kwarg['train_type'] = cf.get(\"Model\", \"type\")\n",
    "\n",
    "        # 训练轮数\n",
    "        if cf.has_option(\"Model\", \"epochs\"):\n",
    "            kwarg['train_epoch'] = int(cf.get(\"Model\", \"epochs\"))\n",
    "\n",
    "        # 算法中间的中间层数，以及输出层数\n",
    "        if cf.has_option(\"Model\", \"model_layer\"):\n",
    "            kwarg['model_layer'] = json.loads(cf.get(\"Model\", \"model_layer\"))\n",
    "\n",
    "        # 将结果输出的路径\n",
    "        if cf.has_option(\"Output\", \"path\"):\n",
    "            kwarg['outfile_path'] = cf.get(\"Output\", \"path\")\n",
    "        else:\n",
    "            kwarg['outfile_path'] = os.path.join(kwarg['root'], \"processed\", \"result.rsf\")\n",
    "\n",
    "        # 使用cpu还是gpu\n",
    "        if cf.has_option(\"Device\", \"device\"):\n",
    "            kwarg['device'] = cf.get(\"Device\", \"device\")\n",
    "        # 使用cpu还是gpu\n",
    "        if cf.has_option(\"Model\", \"hidden_layer\"):\n",
    "            kwarg['hidden_layer'] = json.loads(cf.get(\"Model\", \"hidden_layer\"))\n",
    "        if cf.has_option(\"Model\", \"out_layer\"):\n",
    "            kwarg['out_layer'] = json.loads(cf.get(\"Model\", \"out_layer\"))\n",
    "\n",
    "        # ground_truth的路径，默认是None\n",
    "        if cf.has_option(\"Metric\", \"ground_truth_path\"):\n",
    "            kwarg[\"ground_path\"] = cf.get(\"Metric\", \"ground_truth_path\")\n",
    "        else:\n",
    "            kwarg[\"ground_path\"] = None\n",
    "\n",
    "        if cf.has_option(\"optimizer\",\"lr\"):\n",
    "            kwarg[\"lr\"] = float(cf.get(\"optimizer\", \"lr\"))\n",
    "        return kwarg\n",
    "\n",
    "    def Read_unSurpervised_Config(self):\n",
    "        # 读取无监督学习的配置文件\n",
    "        '''\n",
    "        无监督学习使用的是类似与Node2vec的一个算法\n",
    "        所以需要使用的参数比较多\n",
    "        '''\n",
    "        cf = configparser.ConfigParser()\n",
    "        cf.read(self.path)  # 读取配置文件，如果写文件的绝对路径，就可以不用os模块\n",
    "        kwarg = {}\n",
    "        # 数据存储的位置\n",
    "        if cf.has_option(\"Data\", \"path\"):\n",
    "            kwarg['root'] = cf.get(\"Data\", \"path\")\n",
    "\n",
    "        # 项目名称\n",
    "        if cf.has_option(\"Data\", \"project\"):\n",
    "            kwarg['project'] = cf.get(\"Data\", \"project\")\n",
    "\n",
    "        # 数据存储的类别symbol还是文件\n",
    "        if cf.has_option(\"Data\", \"type\"):\n",
    "            kwarg['data_type'] = cf.get(\"Data\", \"type\")\n",
    "\n",
    "        # 判断是选择使用哪个模型\n",
    "        if cf.has_option(\"Model\", \"name\"):\n",
    "            kwarg['model_name'] = cf.get(\"Model\", \"name\")\n",
    "\n",
    "        # 判断模型的类别是半监督还是无监督\n",
    "        if cf.has_option(\"Model\", \"type\"):\n",
    "            kwarg['train_type'] = cf.get(\"Model\", \"type\")\n",
    "\n",
    "        # 训练轮数\n",
    "        if cf.has_option(\"Model\", \"epochs\"):\n",
    "            kwarg['train_epoch'] = int(cf.get(\"Model\", \"epochs\"))\n",
    "\n",
    "        # 算法中间的中间层数，以及输出层数\n",
    "        if cf.has_option(\"Model\", \"model_layer\"):\n",
    "            kwarg['model_layer'] = json.loads(cf.get(\"Model\", \"model_layer\"))\n",
    "\n",
    "        # 将结果输出的路径\n",
    "        if cf.has_option(\"Output\", \"path\"):\n",
    "            kwarg['outfile_path'] = cf.get(\"Output\", \"path\")\n",
    "\n",
    "        # 聚类的聚类数目\n",
    "        if cf.has_option(\"Output\", \"cluster\"):\n",
    "            kwarg['cluster'] = int(cf.get(\"Output\", \"cluster\"))\n",
    "\n",
    "        # 输出的方法。这里是指如果使用的是symbol；是使用average进行最终的embedding，还是使用vote？\n",
    "        if cf.has_option(\"Output\", \"method\"):\n",
    "            kwarg['out_method'] = cf.get(\"Output\", \"method\")\n",
    "\n",
    "        # 使用cpu还是gpu\n",
    "        if cf.has_option(\"Device\", \"device\"):\n",
    "            kwarg['device'] = cf.get(\"Device\", \"device\")\n",
    "\n",
    "        # ground_truth的路径，默认是None\n",
    "        if cf.has_option(\"Metric\", \"ground_truth_path\"):\n",
    "            kwarg[\"ground_path\"] = cf.get(\"Metric\", \"ground_truth_path\")\n",
    "        else:\n",
    "            kwarg[\"ground_path\"] = None\n",
    "        if cf.has_option(\"optimizer\",\"lr\"):\n",
    "            kwarg[\"lr\"] = float(cf.get(\"optimizer\", \"lr\"))\n",
    "\n",
    "        # 是否用了node2vec的随机游走来作为loss function\n",
    "        if cf.has_section(\"NodeGcn\"):\n",
    "            kwarg.update(self.Read_randomwalk_Config())\n",
    "        return kwarg\n",
    "\n",
    "    def Read_randomwalk_Config(self):\n",
    "        '''\n",
    "        读取node2vec_gcn的参数\n",
    "        Node2Vec(data.edge_index,\n",
    "        embedding_dim=128, #参数的配置在\"Model\", \"model_layer\"中最后的参数。\n",
    "        walk_length=20,\n",
    "        context_size=10, walks_per_node=10,\n",
    "        num_negative_samples=1,\n",
    "        p=1,\n",
    "        q=1,\n",
    "        sparse=True)\n",
    "        '''\n",
    "        cf = configparser.ConfigParser()\n",
    "        cf.read(self.path)  # 读取配置文件，如果写文件的绝对路径，就可以不用os模块\n",
    "        kwarg = {}\n",
    "        # walk_length\n",
    "        if cf.has_option(\"NodeGcn\", \"walk_length\"):\n",
    "            kwarg['walk_length'] = int(cf.get(\"NodeGcn\", \"walk_length\"))\n",
    "        # context_size\n",
    "        if cf.has_option(\"NodeGcn\", \"context_size\"):\n",
    "            kwarg['context_size'] = int(cf.get(\"NodeGcn\", \"context_size\"))\n",
    "\n",
    "        # walks_per_node\n",
    "        if cf.has_option(\"NodeGcn\", \"walks_per_node\"):\n",
    "            kwarg['walks_per_node'] = int(cf.get(\"NodeGcn\", \"walks_per_node\"))\n",
    "\n",
    "        # p\n",
    "        if cf.has_option(\"NodeGcn\", \"p\"):\n",
    "            kwarg['p'] = float(cf.get(\"NodeGcn\", \"p\"))\n",
    "\n",
    "        # q\n",
    "        if cf.has_option(\"NodeGcn\", \"q\"):\n",
    "            kwarg['q'] = float(cf.get(\"NodeGcn\", \"q\"))\n",
    "\n",
    "        # 算法中间的中间层数，以及输出层数\n",
    "        if cf.has_option(\"NodeGcn\", \"num_negative_samples\"):\n",
    "            kwarg['num_negative_samples'] = float(cf.get(\"NodeGcn\", \"num_negative_samples\"))\n",
    "        return kwarg\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "voluntary-glenn",
   "metadata": {},
   "outputs": [],
   "source": [
    "import argparse\n",
    "import os\n",
    "import shutil\n",
    "import sys\n",
    "rootPath = \"/Users/wzx/Downloads/module-reverse-by-gnn\"\n",
    "sys.path.append(rootPath)\n",
    "from ProcessData.Process import SymbolVector, FileVector\n",
    "from sklearn.metrics.pairwise import cosine_similarity\n",
    "import argparse\n",
    "from sklearn.cluster import KMeans\n",
    "\n",
    "from Metric import Metric\n",
    "from Output.output_mehod.result2rsf_file import result2rsf_file\n",
    "from ProcessData import DependenceGraph,FileVectorDependenceGraph,FileVectorDependenceGraph_rmgr\n",
    "from Model.Module.Gcnconv1 import Gcnconv1\n",
    "from Model.Module.Gcnconv2 import Gcnconv2\n",
    "from Model.Module.Gatconv1 import Gatconv1\n",
    "from Model.Module.Gatconv2 import Gatconv2\n",
    "import torch\n",
    "from Model.Module.GraphSageconv1 import GraphSageconv1\n",
    "from Model.Module.GraphSageconv2 import GraphSageconv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "institutional-values",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[31msymbol.mdg节点的数量：2457\u001b[0m\n",
      "\u001b[31m符号vector的数量：1153\u001b[0m\n",
      "\u001b[31m符号vector的维度：300\u001b[0m\n",
      "\u001b[32m提取的符号文件有245个\u001b[0m\n",
      "\u001b[32m提取的符号中，包含字符的文件有175个\u001b[0m\n",
      "边的数量: 3332\n",
      "删除掉的边的数量: 5805\n",
      "\u001b[32m图中节点总数：353个\u001b[0m\n",
      "\u001b[32m图中节点，含有初始vector：175个\u001b[0m\n",
      "\u001b[32m图中节点，初始vector为全1的：178个\u001b[0m\n",
      "含有vector的文件: 175\n",
      "['alias.c', 'alias.h', 'builtins/mkbuiltins.c', 'command.h', 'externs.h', 'general.h', 'hashlib.c', 'hashlib.h', 'lib/readline/complete.c', 'lib/readline/funmap.c', 'lib/readline/histlib.h', 'lib/readline/tilde.c', 'lib/readline/vi_mode.c', 'lib/readline/xmalloc.h', 'lib/sh/mbschr.c', 'lib/sh/stringvec.c', 'lib/tilde/tilde.c', 'pcomplete.c', 'pcomplete.h', 'xmalloc.c', 'xmalloc.h', 'array.c', 'arrayfunc.h', 'array.h', 'assoc.h', 'builtins/common.h', 'dispose_cmd.h', 'error.h', 'lib/glob/smatch.c', 'lib/glob/xmbsrtowcs.c', 'lib/readline/rlshell.h', 'lib/readline/shell.c', 'lib/sh/casemod.c', 'lib/sh/itos.c', 'lib/sh/shquote.c', 'make_cmd.c', 'make_cmd.h', 'shell.h', 'sig.h', 'subst.c', 'subst.h', 'unwind_prot.h', 'variables.h', 'arrayfunc.c', 'assoc.c', 'bashline.c', 'builtins/common.c', 'builtins/evalfile.c', 'builtins/evalstring.c', 'dispose_cmd.c', 'error.c', 'eval.c', 'execute_cmd.c', 'expr.c', 'general.c', 'include/shmbutil.h', 'jobs.c', 'pathexp.c', 'pathexp.h', 'redir.c', 'shell.c', 'sig.c', 'stringlib.c', 'trap.c', 'variables.c', 'y.tab.c', 'bashhist.c', 'bashhist.h', 'bashline.h', 'flags.c', 'flags.h', 'input.h', 'lib/glob/glob.c', 'lib/glob/glob.h', 'lib/glob/strmatch.c', 'lib/glob/strmatch.h', 'lib/readline/histexpand.c', 'lib/readline/histfile.c', 'lib/readline/history.c', 'lib/readline/history.h', 'lib/readline/readline.c', 'lib/readline/readline.h', 'lib/sh/unicode.c', 'execute_cmd.h', 'findcmd.c', 'findcmd.h', 'lib/readline/bind.c', 'lib/readline/compat.c', 'lib/readline/display.c', 'lib/readline/input.c', 'lib/readline/keymaps.c', 'lib/readline/keymaps.h', 'lib/readline/kill.c', 'lib/readline/macro.c', 'lib/readline/misc.c', 'lib/readline/rltty.c', 'lib/readline/tcap.h', 'lib/readline/terminal.c', 'lib/readline/text.c', 'lib/readline/tilde.h', 'lib/readline/undo.c', 'lib/readline/util.c', 'lib/sh/fnxform.c', 'lib/sh/makepath.c', 'lib/sh/pathcanon.c', 'lib/sh/pathphys.c', 'lib/sh/shmatch.c', 'lib/sh/spell.c', 'lib/termcap/termcap.c', 'pcomplib.c', 'support/bashversion.c', 'version.c', 'braces.c', 'builtins/bashgetopt.c', 'builtins/bashgetopt.h', 'unwind_prot.c', 'builtins/builtext.h', 'lib/tilde/tilde.h', 'copy_cmd.c', 'input.c', 'jobs.h', 'lib/sh/fpurge.c', 'trap.h', 'lib/sh/stringlist.c', 'print_cmd.c', 'lib/sh/strtrans.c', 'lib/sh/zmapfd.c', 'lib/malloc/malloc.c', 'lib/readline/xfree.c', 'lib/sh/zcatfd.c', 'redir.h', 'lib/sh/tmpfile.c', 'builtins/getopt.c', 'builtins/getopt.h', 'hashcmd.c', 'hashcmd.h', 'lib/sh/zgetline.c', 'lib/sh/zread.c', 'lib/readline/rlmbutil.h', 'mailcheck.c', 'builtins/psize.c', 'lib/readline/signals.c', 'lib/sh/uconvert.c', 'test.c', 'test.h', 'lib/sh/timeval.c', 'lib/sh/oslib.c', 'list.c', 'lib/sh/fmtumax.c', 'lib/sh/eaccess.c', 'lib/sh/shmbchar.c', 'lib/sh/winsize.c', 'lib/glob/gmisc.c', 'lib/sh/getenv.c', 'lib/malloc/shmalloc.h', 'lib/readline/xmalloc.c', 'lib/readline/isearch.c', 'lib/readline/mbutil.c', 'lib/readline/rlprivate.h', 'lib/readline/callback.c', 'lib/readline/search.c', 'lib/termcap/tparam.c', 'lib/readline/nls.c', 'lib/sh/fmtullong.c', 'lib/sh/fmtulong.c', 'locale.c', 'lib/sh/mailstat.c', 'lib/sh/mbscasecmp.c', 'lib/sh/mbscmp.c', 'lib/sh/netconn.c', 'lib/sh/setlinebuf.c', 'mailcheck.h', 'mksyntax.c', 'support/mksignames.c', 'support/signames.c']\n",
      "提取的了文件，但是文件中的函数没有初始vector: 70\n",
      "['bashansi.h', 'bashtypes.h', 'config-bot.h', 'config.h', 'config-top.h', 'include/chartypes.h', 'include/stdc.h', 'lib/malloc/imalloc.h', 'lib/readline/chardefs.h', 'lib/readline/rldefs.h', 'bashjmp.h', 'conftypes.h', 'include/maxpath.h', 'include/ocache.h', 'include/posixjmp.h', 'pathnames.h', 'quit.h', 'syntax.h', 'bashintl.h', 'include/gettext.h', 'include/shmbchar.h', 'include/filecntl.h', 'include/posixstat.h', 'lib/readline/histsearch.c', 'lib/readline/rlstdc.h', 'lib/readline/rltypedefs.h', 'parser.h', 'lib/readline/posixjmp.h', 'bracecomp.c', 'builtins/builtins.c', 'builtins.h', 'lib/readline/emacs_keymap.c', 'lib/readline/rlconf.h', 'lib/readline/vi_keymap.c', 'syntax.c', 'include/posixdir.h', 'include/posixwait.h', 'siglist.h', 'include/typemax.h', 'y.tab.h', 'include/memalloc.h', 'include/posixtime.h', 'include/shtty.h', 'lib/sh/input_avail.c', 'lib/sh/shtty.c', 'lib/sh/ufuncs.c', 'version.h', 'lib/readline/posixstat.h', 'lib/readline/posixdir.h', 'include/posixselect.h', 'lib/readline/posixselect.h', 'lib/glob/collsyms.h', 'lib/glob/glob_loop.c', 'lib/glob/sm_loop.c', 'lib/malloc/table.c', 'lib/malloc/table.h', 'lib/malloc/trace.c', 'lib/malloc/watch.c', 'lib/readline/parens.c', 'lib/readline/savestring.c', 'lib/readline/rltty.h', 'lib/readline/rlwinsize.h', 'lib/sh/clktck.c', 'lib/sh/clock.c', 'lib/sh/netopen.c', 'lib/sh/snprintf.c', 'lib/sh/zwrite.c', 'lib/termcap/ltcap.h', 'signames.h', 'patchlevel.h']\n",
      "没有提取到文件: 108\n",
      "['lib/intl/relocatable.c', 'lib/malloc/xmalloc.c', 'builtins/break.c', 'builtins/builtin.c', 'builtins/cd.c', 'builtins/declare.c', 'builtins/exit.c', 'builtins/fg_bg.c', 'builtins/getopts.c', 'builtins/hash.c', 'builtins/return.c', 'builtins/setattr.c', 'builtins/source.c', 'builtins/test.c', 'builtins/type.c', 'nojobs.c', 'builtins/fc.c', 'builtins/history.c', 'builtins/shopt.c', 'lib/sh/strftime.c', 'lib/intl/libgnuintl.h', 'builtins/alias.c', 'builtins/echo.c', 'builtins/kill.c', 'builtins/set.c', 'builtins/trap.c', 'builtins/ulimit.c', 'lib/sh/strstr.c', 'lib/sh/strtoimax.c', 'builtins/bind.c', 'builtins/enable.c', 'builtins/caller.c', 'builtins/colon.c', 'builtins/command.c', 'builtins/complete.c', 'builtins/eval.c', 'builtins/exec.c', 'builtins/help.c', 'builtins/jobs.c', 'builtins/let.c', 'builtins/mapfile.c', 'builtins/printf.c', 'builtins/pushd.c', 'builtins/read.c', 'builtins/shift.c', 'builtins/suspend.c', 'builtins/times.c', 'builtins/umask.c', 'builtins/wait.c', 'lib/intl/dcigettext.c', 'lib/sh/strcasestr.c', 'lib/sh/strtoumax.c', 'builtins/pipesize.h', 'lib/intl/loadmsgcat.c', 'lib/intl/localealias.c', 'lib/intl/l10nflist.c', 'lib/sh/strchrnul.c', 'lib/intl/bindtextdom.c', 'lib/intl/gettextP.h', 'lib/intl/gmo.h', 'lib/intl/loadinfo.h', 'lib/intl/os2compat.c', 'lib/intl/plural-exp.h', 'lib/intl/textdomain.c', 'lib/intl/dcgettext.c', 'lib/intl/dcngettext.c', 'lib/intl/dgettext.c', 'lib/intl/gettext.c', 'lib/intl/eval-plural.h', 'lib/intl/finddomain.c', 'lib/intl/hash-string.h', 'lib/intl/localcharset.c', 'lib/intl/localename.c', 'lib/intl/log.c', 'lib/intl/dngettext.c', 'lib/intl/ngettext.c', 'lib/intl/explodename.c', 'lib/intl/intl-compat.c', 'lib/intl/localcharset.h', 'lib/intl/relocatable.h', 'lib/intl/plural.c', 'lib/intl/plural-exp.c', 'lib/malloc/alloca.c', 'lib/malloc/stats.c', 'lib/sh/dprintf.c', 'lib/sh/getcwd.c', 'support/printenv.c', 'lib/sh/inet_aton.c', 'lib/sh/mktime.c', 'lib/sh/rename.c', 'lib/sh/strcasecmp.c', 'lib/sh/strerror.c', 'lib/sh/strnlen.c', 'lib/sh/strpbrk.c', 'lib/sh/strtod.c', 'lib/sh/strtol.c', 'lib/sh/strtoll.c', 'lib/sh/strtoul.c', 'lib/sh/strtoull.c', 'lib/sh/times.c', 'lib/sh/vprint.c', 'lib/sh/wcsdup.c', 'lib/sh/wcswidth.c', 'lib/tilde/shell.c', 'siglist.c', 'support/man2html.c', 'support/recho.c', 'support/zecho.c']\n",
      "Processing...\n",
      "Done!\n",
      "\u001b[32m======================\u001b[0m\n",
      "\u001b[32mNumber of nodes: 353\u001b[0m\n",
      "\u001b[32mNumber of edges: 9137\u001b[0m\n",
      "\u001b[32mAverage node degree: 25.88\u001b[0m\n",
      "\u001b[32mNumber of training nodes: 211\u001b[0m\n",
      "\u001b[32mTraining node label rate: 0.60\u001b[0m\n",
      "\u001b[32mContains isolated nodes: False\u001b[0m\n",
      "\u001b[32mContains self-loops: False\u001b[0m\n",
      "\u001b[32mIs undirected: False\u001b[0m\n",
      "\u001b[32mData's dimension: 300\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "config=\"/Users/wzx/Downloads/module-reverse-by-gnn/config/client/File_symbol_vector_un/symbol.ini\"\n",
    "kwarg = ConfigFile(config).ReadConfig()\n",
    "if kwarg[\"data_type\"] == \"symbol\":\n",
    "    FileVector(kwarg['root'])\n",
    "\n",
    "if os.path.exists(os.path.join(kwarg[\"root\"], \"processed\")):\n",
    "    shutil.rmtree(os.path.join(kwarg[\"root\"], \"processed\"))\n",
    "dataset = FileVectorDependenceGraph_rmgr(kwarg[\"root\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "legal-alpha",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = dataset[0]\n",
    "#归一化\n",
    "data.x = data.x / data.x.sum(1, keepdim=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "published-disclosure",
   "metadata": {},
   "source": [
    "# 二、计算文件相关性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "positive-arizona",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>343</th>\n",
       "      <th>344</th>\n",
       "      <th>345</th>\n",
       "      <th>346</th>\n",
       "      <th>347</th>\n",
       "      <th>348</th>\n",
       "      <th>349</th>\n",
       "      <th>350</th>\n",
       "      <th>351</th>\n",
       "      <th>352</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.271684</td>\n",
       "      <td>0.135784</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.088912</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002946</td>\n",
       "      <td>0.107471</td>\n",
       "      <td>0.004290</td>\n",
       "      <td>0.152188</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.271684</td>\n",
       "      <td>0.135784</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.088912</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002946</td>\n",
       "      <td>0.107471</td>\n",
       "      <td>0.004290</td>\n",
       "      <td>0.152188</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.150426</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.038584</td>\n",
       "      <td>...</td>\n",
       "      <td>0.049082</td>\n",
       "      <td>0.061616</td>\n",
       "      <td>0.041948</td>\n",
       "      <td>0.153747</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.150426</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.038584</td>\n",
       "      <td>...</td>\n",
       "      <td>0.049082</td>\n",
       "      <td>0.061616</td>\n",
       "      <td>0.041948</td>\n",
       "      <td>0.153747</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.271684</td>\n",
       "      <td>0.271684</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.149504</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.013731</td>\n",
       "      <td>...</td>\n",
       "      <td>0.144501</td>\n",
       "      <td>0.120475</td>\n",
       "      <td>0.087559</td>\n",
       "      <td>0.308908</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.014957</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>348</th>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.150426</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.038584</td>\n",
       "      <td>...</td>\n",
       "      <td>0.049082</td>\n",
       "      <td>0.061616</td>\n",
       "      <td>0.041948</td>\n",
       "      <td>0.153747</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>349</th>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.150426</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.038584</td>\n",
       "      <td>...</td>\n",
       "      <td>0.049082</td>\n",
       "      <td>0.061616</td>\n",
       "      <td>0.041948</td>\n",
       "      <td>0.153747</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.150426</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.038584</td>\n",
       "      <td>...</td>\n",
       "      <td>0.049082</td>\n",
       "      <td>0.061616</td>\n",
       "      <td>0.041948</td>\n",
       "      <td>0.153747</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>351</th>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.150426</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.038584</td>\n",
       "      <td>...</td>\n",
       "      <td>0.049082</td>\n",
       "      <td>0.061616</td>\n",
       "      <td>0.041948</td>\n",
       "      <td>0.153747</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>352</th>\n",
       "      <td>0.009336</td>\n",
       "      <td>0.009336</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.014957</td>\n",
       "      <td>0.150426</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.038584</td>\n",
       "      <td>...</td>\n",
       "      <td>0.049082</td>\n",
       "      <td>0.061616</td>\n",
       "      <td>0.041948</td>\n",
       "      <td>0.153747</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>353 rows × 353 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6    \\\n",
       "0    1.000000  1.000000  0.009336  0.009336  0.271684  0.135784  0.009336   \n",
       "1    1.000000  1.000000  0.009336  0.009336  0.271684  0.135784  0.009336   \n",
       "2    0.009336  0.009336  1.000000  1.000000  0.014957  0.150426  1.000000   \n",
       "3    0.009336  0.009336  1.000000  1.000000  0.014957  0.150426  1.000000   \n",
       "4    0.271684  0.271684  0.014957  0.014957  1.000000  0.149504  0.014957   \n",
       "..        ...       ...       ...       ...       ...       ...       ...   \n",
       "348  0.009336  0.009336  1.000000  1.000000  0.014957  0.150426  1.000000   \n",
       "349  0.009336  0.009336  1.000000  1.000000  0.014957  0.150426  1.000000   \n",
       "350  0.009336  0.009336  1.000000  1.000000  0.014957  0.150426  1.000000   \n",
       "351  0.009336  0.009336  1.000000  1.000000  0.014957  0.150426  1.000000   \n",
       "352  0.009336  0.009336  1.000000  1.000000  0.014957  0.150426  1.000000   \n",
       "\n",
       "          7         8         9    ...       343       344       345  \\\n",
       "0    0.009336  0.009336  0.088912  ...  0.002946  0.107471  0.004290   \n",
       "1    0.009336  0.009336  0.088912  ...  0.002946  0.107471  0.004290   \n",
       "2    1.000000  1.000000  0.038584  ...  0.049082  0.061616  0.041948   \n",
       "3    1.000000  1.000000  0.038584  ...  0.049082  0.061616  0.041948   \n",
       "4    0.014957  0.014957  0.013731  ...  0.144501  0.120475  0.087559   \n",
       "..        ...       ...       ...  ...       ...       ...       ...   \n",
       "348  1.000000  1.000000  0.038584  ...  0.049082  0.061616  0.041948   \n",
       "349  1.000000  1.000000  0.038584  ...  0.049082  0.061616  0.041948   \n",
       "350  1.000000  1.000000  0.038584  ...  0.049082  0.061616  0.041948   \n",
       "351  1.000000  1.000000  0.038584  ...  0.049082  0.061616  0.041948   \n",
       "352  1.000000  1.000000  0.038584  ...  0.049082  0.061616  0.041948   \n",
       "\n",
       "          346       347       348       349       350       351       352  \n",
       "0    0.152188  0.009336  0.009336  0.009336  0.009336  0.009336  0.009336  \n",
       "1    0.152188  0.009336  0.009336  0.009336  0.009336  0.009336  0.009336  \n",
       "2    0.153747  1.000000  1.000000  1.000000  1.000000  1.000000  1.000000  \n",
       "3    0.153747  1.000000  1.000000  1.000000  1.000000  1.000000  1.000000  \n",
       "4    0.308908  0.014957  0.014957  0.014957  0.014957  0.014957  0.014957  \n",
       "..        ...       ...       ...       ...       ...       ...       ...  \n",
       "348  0.153747  1.000000  1.000000  1.000000  1.000000  1.000000  1.000000  \n",
       "349  0.153747  1.000000  1.000000  1.000000  1.000000  1.000000  1.000000  \n",
       "350  0.153747  1.000000  1.000000  1.000000  1.000000  1.000000  1.000000  \n",
       "351  0.153747  1.000000  1.000000  1.000000  1.000000  1.000000  1.000000  \n",
       "352  0.153747  1.000000  1.000000  1.000000  1.000000  1.000000  1.000000  \n",
       "\n",
       "[353 rows x 353 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "m = cosine_similarity(data.x)\n",
    "m = np.maximum(m, -m)\n",
    "pd.DataFrame(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "hired-contest",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.18413807"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[dataset.dic[\"y.tab.c\"]][dataset.dic[\"eval.c\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "sunset-coordinate",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.03253296"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[dataset.dic[\"y.tab.c\"]][dataset.dic[\"externs.h\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "listed-knight",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.22284347"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[dataset.dic[\"eval.c\"]][dataset.dic[\"externs.h\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "yellow-theme",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三、文件的相关新i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 685,
   "id": "hourly-objective",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1     102\n",
       "10     67\n",
       "4      56\n",
       "9      55\n",
       "6      30\n",
       "5      10\n",
       "14      7\n",
       "8       7\n",
       "13      4\n",
       "3       4\n",
       "12      3\n",
       "11      3\n",
       "0       3\n",
       "2       2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 685,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(data.y).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 686,
   "id": "institutional-builder",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>348</th>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>349</th>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>351</th>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>352</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>353 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      0\n",
       "0     1\n",
       "1     1\n",
       "2     1\n",
       "3     1\n",
       "4     4\n",
       "..   ..\n",
       "348  13\n",
       "349  14\n",
       "350  14\n",
       "351  14\n",
       "352   1\n",
       "\n",
       "[353 rows x 1 columns]"
      ]
     },
     "execution_count": 686,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(data.y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 501,
   "id": "cathedral-closing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(1.)"
      ]
     },
     "execution_count": 501,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.x[5].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "exempt-humanity",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np   \n",
    "import heapq\n",
    "\n",
    "def getmaxIndex(metric,n):\n",
    "    max_indexs = heapq.nlargest(n, range(len(metric)), metric.take)\n",
    "    return max_indexs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 503,
   "id": "fluid-leonard",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>True</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>False</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       0\n",
       "0       \n",
       "True   8\n",
       "False  2"
      ]
     },
     "execution_count": 503,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=getmaxIndex(m[0],10)\n",
    "\n",
    "pd.DataFrame(pd.DataFrame(data.y[a]==data.y[0]).value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 687,
   "id": "entertaining-serial",
   "metadata": {},
   "outputs": [],
   "source": [
    "tmp = []\n",
    "caiyang = 10\n",
    "\n",
    "for i in range(len(data.y)):\n",
    "    if data.y[i]==1 or data.y[i]==10 or data.y[i]==9 or data.y[i]==4 or data.y[i]==6 or data.y[i]==5:\n",
    "        listtmp=[]\n",
    "        a=getmaxIndex(m[i],caiyang)\n",
    "        datapd = pd.DataFrame(data.y[a]==data.y[0]).value_counts()\n",
    "        simnum=0\n",
    "        diftnum=0\n",
    "\n",
    "        if True in datapd:\n",
    "            simnum = (int)(datapd[True])\n",
    "        if False in datapd:\n",
    "            diftnum = (int)(datapd[False])\n",
    "\n",
    "        listtmp.append(simnum)\n",
    "        listtmp.append(diftnum)\n",
    "        tmp.append(listtmp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 688,
   "id": "ongoing-humidity",
   "metadata": {},
   "outputs": [],
   "source": [
    "tt=pd.DataFrame(tmp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 695,
   "id": "transsexual-sigma",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>305</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>306</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>307</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>308</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>309</th>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>310 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     0  1\n",
       "0    7  3\n",
       "1    7  3\n",
       "2    8  2\n",
       "3    8  2\n",
       "4    5  5\n",
       "..  .. ..\n",
       "305  8  2\n",
       "306  8  2\n",
       "307  8  2\n",
       "308  8  2\n",
       "309  8  2\n",
       "\n",
       "[310 rows x 2 columns]"
      ]
     },
     "execution_count": 695,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tt[:-10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 690,
   "id": "incorporated-farming",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1364"
      ]
     },
     "execution_count": 690,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 不相似的\n",
    "tt[1].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 691,
   "id": "numerous-billy",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1836"
      ]
     },
     "execution_count": 691,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 相似的\n",
    "tt[0].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "silent-guest",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 初步判断语义没有太明显"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "id": "cross-windows",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32m======================\u001b[0m\n",
      "\u001b[32mNumber of nodes: 236\u001b[0m\n",
      "\u001b[32mNumber of edges: 2512\u001b[0m\n",
      "\u001b[32mAverage node degree: 10.64\u001b[0m\n",
      "\u001b[32mNumber of training nodes: 141\u001b[0m\n",
      "\u001b[32mTraining node label rate: 0.60\u001b[0m\n",
      "\u001b[32mContains isolated nodes: False\u001b[0m\n",
      "\u001b[32mContains self-loops: False\u001b[0m\n",
      "\u001b[32mIs undirected: False\u001b[0m\n",
      "\u001b[32mData's dimension: 300\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "fvector = FileVectorDependenceGraph_rmgr(kwarg[\"root\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "id": "compressed-spider",
   "metadata": {},
   "outputs": [],
   "source": [
    "data=fvector.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 425,
   "id": "developing-liability",
   "metadata": {},
   "outputs": [],
   "source": [
    "from torch_geometric.datasets import Planetoid\n",
    "import torch\n",
    "dataset = Planetoid(root='./cora/',name='Cora')\n",
    "data = dataset[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 426,
   "id": "likely-collect",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    818\n",
       "4    426\n",
       "2    418\n",
       "0    351\n",
       "5    298\n",
       "1    217\n",
       "6    180\n",
       "dtype: int64"
      ]
     },
     "execution_count": 426,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(data.y).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 427,
   "id": "transsexual-aquarium",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>2698</th>\n",
       "      <th>2699</th>\n",
       "      <th>2700</th>\n",
       "      <th>2701</th>\n",
       "      <th>2702</th>\n",
       "      <th>2703</th>\n",
       "      <th>2704</th>\n",
       "      <th>2705</th>\n",
       "      <th>2706</th>\n",
       "      <th>2707</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.069505</td>\n",
       "      <td>0.076472</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.078567</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.145479</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.072739</td>\n",
       "      <td>0.152944</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.208514</td>\n",
       "      <td>0.111111</td>\n",
       "      <td>0.078567</td>\n",
       "      <td>0.178174</td>\n",
       "      <td>0.184900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.069505</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.143509</td>\n",
       "      <td>0.136505</td>\n",
       "      <td>0.049147</td>\n",
       "      <td>0.115663</td>\n",
       "      <td>0.098295</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.046625</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.045502</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.045502</td>\n",
       "      <td>0.191346</td>\n",
       "      <td>0.098295</td>\n",
       "      <td>0.043478</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.098295</td>\n",
       "      <td>0.055728</td>\n",
       "      <td>0.057831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.076472</td>\n",
       "      <td>0.143509</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.150188</td>\n",
       "      <td>0.108148</td>\n",
       "      <td>0.127257</td>\n",
       "      <td>0.162221</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.153897</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.100125</td>\n",
       "      <td>0.052632</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.105263</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.047836</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.108148</td>\n",
       "      <td>0.061314</td>\n",
       "      <td>0.063628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.136505</td>\n",
       "      <td>0.150188</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.121046</td>\n",
       "      <td>0.102869</td>\n",
       "      <td>0.116642</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.047619</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.051434</td>\n",
       "      <td>0.091003</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.078567</td>\n",
       "      <td>0.049147</td>\n",
       "      <td>0.108148</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.065372</td>\n",
       "      <td>0.055556</td>\n",
       "      <td>0.062994</td>\n",
       "      <td>0.105409</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.051434</td>\n",
       "      <td>0.054074</td>\n",
       "      <td>0.102869</td>\n",
       "      <td>0.054074</td>\n",
       "      <td>0.111111</td>\n",
       "      <td>0.098295</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.111111</td>\n",
       "      <td>0.062994</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2703</th>\n",
       "      <td>0.208514</td>\n",
       "      <td>0.043478</td>\n",
       "      <td>0.047836</td>\n",
       "      <td>0.091003</td>\n",
       "      <td>0.098295</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.049147</td>\n",
       "      <td>0.055728</td>\n",
       "      <td>0.046625</td>\n",
       "      <td>0.120386</td>\n",
       "      <td>...</td>\n",
       "      <td>0.136505</td>\n",
       "      <td>0.047836</td>\n",
       "      <td>0.045502</td>\n",
       "      <td>0.095673</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.049147</td>\n",
       "      <td>0.111456</td>\n",
       "      <td>0.115663</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2704</th>\n",
       "      <td>0.111111</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.145479</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.145479</td>\n",
       "      <td>0.076472</td>\n",
       "      <td>0.078567</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.089087</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2705</th>\n",
       "      <td>0.078567</td>\n",
       "      <td>0.098295</td>\n",
       "      <td>0.108148</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.111111</td>\n",
       "      <td>0.130744</td>\n",
       "      <td>0.055556</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.052705</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.051434</td>\n",
       "      <td>0.054074</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.049147</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.065372</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2706</th>\n",
       "      <td>0.178174</td>\n",
       "      <td>0.055728</td>\n",
       "      <td>0.061314</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.062994</td>\n",
       "      <td>0.074125</td>\n",
       "      <td>0.062994</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.119523</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.174964</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.058321</td>\n",
       "      <td>0.122628</td>\n",
       "      <td>0.062994</td>\n",
       "      <td>0.111456</td>\n",
       "      <td>0.089087</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.148250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2707</th>\n",
       "      <td>0.184900</td>\n",
       "      <td>0.057831</td>\n",
       "      <td>0.063628</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.076923</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.074125</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.121046</td>\n",
       "      <td>0.063628</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.127257</td>\n",
       "      <td>0.196116</td>\n",
       "      <td>0.115663</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.065372</td>\n",
       "      <td>0.148250</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2708 rows × 2708 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6     \\\n",
       "0     1.000000  0.069505  0.076472  0.000000  0.078567  0.000000  0.000000   \n",
       "1     0.069505  1.000000  0.143509  0.136505  0.049147  0.115663  0.098295   \n",
       "2     0.076472  0.143509  1.000000  0.150188  0.108148  0.127257  0.162221   \n",
       "3     0.000000  0.136505  0.150188  1.000000  0.000000  0.121046  0.102869   \n",
       "4     0.078567  0.049147  0.108148  0.000000  1.000000  0.065372  0.055556   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "2703  0.208514  0.043478  0.047836  0.091003  0.098295  0.000000  0.049147   \n",
       "2704  0.111111  0.000000  0.000000  0.000000  0.000000  0.000000  0.000000   \n",
       "2705  0.078567  0.098295  0.108148  0.000000  0.111111  0.130744  0.055556   \n",
       "2706  0.178174  0.055728  0.061314  0.000000  0.062994  0.074125  0.062994   \n",
       "2707  0.184900  0.057831  0.063628  0.000000  0.000000  0.076923  0.000000   \n",
       "\n",
       "          7         8         9     ...      2698      2699      2700  \\\n",
       "0     0.000000  0.000000  0.000000  ...  0.145479  0.000000  0.072739   \n",
       "1     0.000000  0.046625  0.000000  ...  0.045502  0.000000  0.045502   \n",
       "2     0.000000  0.153897  0.000000  ...  0.100125  0.052632  0.000000   \n",
       "3     0.116642  0.000000  0.000000  ...  0.047619  0.000000  0.000000   \n",
       "4     0.062994  0.105409  0.000000  ...  0.051434  0.054074  0.102869   \n",
       "...        ...       ...       ...  ...       ...       ...       ...   \n",
       "2703  0.055728  0.046625  0.120386  ...  0.136505  0.047836  0.045502   \n",
       "2704  0.000000  0.000000  0.000000  ...  0.145479  0.000000  0.145479   \n",
       "2705  0.000000  0.052705  0.000000  ...  0.000000  0.000000  0.051434   \n",
       "2706  0.000000  0.119523  0.000000  ...  0.174964  0.000000  0.058321   \n",
       "2707  0.074125  0.000000  0.000000  ...  0.121046  0.063628  0.000000   \n",
       "\n",
       "          2701      2702      2703      2704      2705      2706      2707  \n",
       "0     0.152944  0.000000  0.208514  0.111111  0.078567  0.178174  0.184900  \n",
       "1     0.191346  0.098295  0.043478  0.000000  0.098295  0.055728  0.057831  \n",
       "2     0.105263  0.000000  0.047836  0.000000  0.108148  0.061314  0.063628  \n",
       "3     0.000000  0.051434  0.091003  0.000000  0.000000  0.000000  0.000000  \n",
       "4     0.054074  0.111111  0.098295  0.000000  0.111111  0.062994  0.000000  \n",
       "...        ...       ...       ...       ...       ...       ...       ...  \n",
       "2703  0.095673  0.000000  1.000000  0.000000  0.049147  0.111456  0.115663  \n",
       "2704  0.076472  0.078567  0.000000  1.000000  0.000000  0.089087  0.000000  \n",
       "2705  0.054074  0.000000  0.049147  0.000000  1.000000  0.000000  0.065372  \n",
       "2706  0.122628  0.062994  0.111456  0.089087  0.000000  1.000000  0.148250  \n",
       "2707  0.127257  0.196116  0.115663  0.000000  0.065372  0.148250  1.000000  \n",
       "\n",
       "[2708 rows x 2708 columns]"
      ]
     },
     "execution_count": 427,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = cosine_similarity(data.x)\n",
    "pd.DataFrame(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 428,
   "id": "encouraging-offense",
   "metadata": {},
   "outputs": [],
   "source": [
    "tmp = []\n",
    "caiyang = 300\n",
    "\n",
    "for i in range(len(data.y)):\n",
    "    if data.y[i]==6:\n",
    "        listtmp=[]\n",
    "        a=getmaxIndex(m[i],caiyang)\n",
    "        datapd = pd.DataFrame(data.y[a]==data.y[0]).value_counts()\n",
    "        simnum=0\n",
    "        diftnum=0\n",
    "\n",
    "        if True in datapd:\n",
    "            simnum = (int)(datapd[True])\n",
    "        if False in datapd:\n",
    "            diftnum = (int)(datapd[False])\n",
    "\n",
    "        listtmp.append(simnum)\n",
    "        listtmp.append(diftnum)\n",
    "        tmp.append(listtmp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 429,
   "id": "prompt-devices",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>118</td>\n",
       "      <td>182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>83</td>\n",
       "      <td>217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>52</td>\n",
       "      <td>248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>57</td>\n",
       "      <td>243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>46</td>\n",
       "      <td>254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>42</td>\n",
       "      <td>258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>67</td>\n",
       "      <td>233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>66</td>\n",
       "      <td>234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <td>70</td>\n",
       "      <td>230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>86</td>\n",
       "      <td>214</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>180 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       0    1\n",
       "0    118  182\n",
       "1     83  217\n",
       "2     52  248\n",
       "3     57  243\n",
       "4     46  254\n",
       "..   ...  ...\n",
       "175   42  258\n",
       "176   67  233\n",
       "177   66  234\n",
       "178   70  230\n",
       "179   86  214\n",
       "\n",
       "[180 rows x 2 columns]"
      ]
     },
     "execution_count": 429,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tt=pd.DataFrame(tmp)\n",
    "tt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 430,
   "id": "opponent-century",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "42454"
      ]
     },
     "execution_count": 430,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tt=pd.DataFrame(tmp)\n",
    "tt[1].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 431,
   "id": "former-lincoln",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11546"
      ]
     },
     "execution_count": 431,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tt[0].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 432,
   "id": "sized-forge",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "from torch_geometric.nn import MessagePassing\n",
    "from torch_geometric.utils import add_self_loops, degree\n",
    "\n",
    "class Net(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(Net, self).__init__()\n",
    "        self.conv1 = GCNConv(dataset.num_node_features, 32)\n",
    "        self.conv2 = GCNConv(32, dataset.num_classes)\n",
    "\n",
    "    def forward(self, data):\n",
    "        x, edge_index = data.x, data.edge_index\n",
    "        x = self.conv1(x, edge_index)\n",
    "        x = F.relu(x)\n",
    "        x = F.dropout(x, training=self.training)\n",
    "        x = self.conv2(x, edge_index)\n",
    "        x = F.softmax(x, dim=1)\n",
    "\n",
    "        return x\n",
    "class GCNConv(MessagePassing):\n",
    "    def __init__(self, input_dim, output_dim):\n",
    "        super(GCNConv, self).__init__(aggr='add')\n",
    "        self.fc = nn.Linear(input_dim, output_dim)\n",
    "\n",
    "    def forward(self, x, edge_index):\n",
    "        edge_index, _ = add_self_loops(\n",
    "            edge_index=edge_index, num_nodes=x.shape[0])\n",
    "\n",
    "        x = self.fc(x)\n",
    "\n",
    "        row, col = edge_index\n",
    "        deg = degree(index=col, dtype=x.dtype)\n",
    "        deg_inv_sqrt = deg.pow(-0.5)\n",
    "        norm = deg_inv_sqrt[row] * deg_inv_sqrt[col]\n",
    "\n",
    "        return self.propagate(edge_index, x=x, norm=norm)\n",
    "\n",
    "    def message(self, x_j, norm):\n",
    "        norm = norm.view(-1, 1)\n",
    "        m = norm * x_j\n",
    "        return m\n",
    "    def update(self,aggr_out):\n",
    "        return aggr_out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 433,
   "id": "chicken-department",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch.optim as optim\n",
    "model = Net()\n",
    "criterion = nn.CrossEntropyLoss()\n",
    "optimizer = optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 436,
   "id": "hollow-escape",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 000 train_loss: 1.1770 train_acc: 1.0000\n",
      "Epoch 001 train_loss: 1.1768 train_acc: 1.0000\n",
      "Epoch 002 train_loss: 1.1800 train_acc: 1.0000\n",
      "Epoch 003 train_loss: 1.1782 train_acc: 1.0000\n",
      "Epoch 004 train_loss: 1.1776 train_acc: 1.0000\n",
      "Epoch 005 train_loss: 1.1789 train_acc: 1.0000\n",
      "Epoch 006 train_loss: 1.1770 train_acc: 1.0000\n",
      "Epoch 007 train_loss: 1.1757 train_acc: 1.0000\n",
      "Epoch 008 train_loss: 1.1765 train_acc: 1.0000\n",
      "Epoch 009 train_loss: 1.1765 train_acc: 1.0000\n",
      "Epoch 010 train_loss: 1.1741 train_acc: 1.0000\n",
      "Epoch 011 train_loss: 1.1752 train_acc: 1.0000\n",
      "Epoch 012 train_loss: 1.1798 train_acc: 1.0000\n",
      "Epoch 013 train_loss: 1.1739 train_acc: 1.0000\n",
      "Epoch 014 train_loss: 1.1768 train_acc: 1.0000\n",
      "Epoch 015 train_loss: 1.1736 train_acc: 1.0000\n",
      "Epoch 016 train_loss: 1.1735 train_acc: 1.0000\n",
      "Epoch 017 train_loss: 1.1730 train_acc: 1.0000\n",
      "Epoch 018 train_loss: 1.1759 train_acc: 1.0000\n",
      "Epoch 019 train_loss: 1.1735 train_acc: 1.0000\n",
      "Epoch 020 train_loss: 1.1778 train_acc: 1.0000\n",
      "Epoch 021 train_loss: 1.1740 train_acc: 1.0000\n",
      "Epoch 022 train_loss: 1.1765 train_acc: 1.0000\n",
      "Epoch 023 train_loss: 1.1758 train_acc: 1.0000\n",
      "Epoch 024 train_loss: 1.1775 train_acc: 1.0000\n",
      "Epoch 025 train_loss: 1.1757 train_acc: 1.0000\n",
      "Epoch 026 train_loss: 1.1743 train_acc: 1.0000\n",
      "Epoch 027 train_loss: 1.1773 train_acc: 1.0000\n",
      "Epoch 028 train_loss: 1.1792 train_acc: 1.0000\n",
      "Epoch 029 train_loss: 1.1799 train_acc: 1.0000\n",
      "Epoch 030 train_loss: 1.1782 train_acc: 1.0000\n",
      "Epoch 031 train_loss: 1.1743 train_acc: 1.0000\n",
      "Epoch 032 train_loss: 1.1797 train_acc: 1.0000\n",
      "Epoch 033 train_loss: 1.1793 train_acc: 1.0000\n",
      "Epoch 034 train_loss: 1.1745 train_acc: 1.0000\n",
      "Epoch 035 train_loss: 1.1755 train_acc: 1.0000\n",
      "Epoch 036 train_loss: 1.1782 train_acc: 1.0000\n",
      "Epoch 037 train_loss: 1.1757 train_acc: 1.0000\n",
      "Epoch 038 train_loss: 1.1752 train_acc: 1.0000\n",
      "Epoch 039 train_loss: 1.1787 train_acc: 1.0000\n",
      "Epoch 040 train_loss: 1.1765 train_acc: 1.0000\n",
      "Epoch 041 train_loss: 1.1753 train_acc: 1.0000\n",
      "Epoch 042 train_loss: 1.1761 train_acc: 1.0000\n",
      "Epoch 043 train_loss: 1.1769 train_acc: 1.0000\n",
      "Epoch 044 train_loss: 1.1766 train_acc: 1.0000\n",
      "Epoch 045 train_loss: 1.1755 train_acc: 1.0000\n",
      "Epoch 046 train_loss: 1.1745 train_acc: 1.0000\n",
      "Epoch 047 train_loss: 1.1834 train_acc: 1.0000\n",
      "Epoch 048 train_loss: 1.1746 train_acc: 1.0000\n",
      "Epoch 049 train_loss: 1.1747 train_acc: 1.0000\n"
     ]
    }
   ],
   "source": [
    "import torch.nn.functional as F\n",
    "model.train()\n",
    "for epoch in range(50):\n",
    "    out = model(data)\n",
    "    loss = criterion(out[data.train_mask], data.y[data.train_mask])\n",
    "\n",
    "    optimizer.zero_grad()\n",
    "    loss.backward()\n",
    "    optimizer.step()\n",
    "\n",
    "    _, pred = torch.max(out[data.train_mask], dim=1)\n",
    "    correct = (pred == data.y[data.train_mask]).sum().item()\n",
    "    acc = correct/data.train_mask.sum().item()\n",
    "\n",
    "    print('Epoch {:03d} train_loss: {:.4f} train_acc: {:.4f}'.format(\n",
    "        epoch, loss.item(), acc))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 437,
   "id": "planned-outline",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test_loss: 1.3932 test_acc: 0.8080\n"
     ]
    }
   ],
   "source": [
    "model.eval()\n",
    "out = model(data)\n",
    "loss = criterion(out[data.test_mask], data.y[data.test_mask])\n",
    "_, pred = torch.max(out[data.test_mask], dim=1)\n",
    "correct = (pred == data.y[data.test_mask]).sum().item()\n",
    "acc = correct/data.test_mask.sum().item()\n",
    "print(\"test_loss: {:.4f} test_acc: {:.4f}\".format(loss.item(), acc))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 439,
   "id": "powerful-philippines",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([3, 4, 4,  ..., 3, 3, 3])"
      ]
     },
     "execution_count": 439,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.y\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "confused-convenience",
   "metadata": {},
   "source": [
    "# 为什么不行原因"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 310,
   "id": "baking-clearance",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([ True,  True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "         True,  True,  True, False,  True,  True,  True,  True,  True,  True,\n",
       "         True, False,  True,  True,  True,  True,  True,  True,  True, False,\n",
       "         True,  True,  True,  True,  True,  True,  True, False,  True,  True,\n",
       "         True,  True,  True,  True,  True,  True,  True, False, False, False,\n",
       "        False,  True,  True,  True, False,  True, False, False, False, False,\n",
       "        False,  True,  True, False, False, False, False, False, False,  True,\n",
       "        False,  True, False,  True,  True, False,  True,  True,  True,  True,\n",
       "         True, False,  True,  True, False,  True,  True,  True, False,  True,\n",
       "        False,  True,  True,  True,  True,  True,  True,  True,  True, False,\n",
       "         True, False,  True, False, False, False, False, False,  True, False,\n",
       "        False,  True, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False, False,\n",
       "        False, False, False, False, False, False, False, False, False,  True,\n",
       "         True,  True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "        False,  True,  True,  True,  True,  True,  True,  True,  True, False,\n",
       "         True,  True,  True,  True, False,  True])"
      ]
     },
     "execution_count": 310,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.y==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "id": "novel-mississippi",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'fvector' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-166-e8f05e39dab0>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m#看一下文件中包含的符号\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfvector\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdic\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'fvector' is not defined"
     ]
    }
   ],
   "source": [
    "#看一下文件中包含的符号\n",
    "list(fvector.dic.keys())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "first-portuguese",
   "metadata": {},
   "source": [
    "# 1、统计符号的相似性。\n",
    "# 2、统计相同的label的文件内部，符号之间的相似性。\n",
    "# 3、统计相同的label的文件包含的符号是否相近。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "automated-miracle",
   "metadata": {},
   "outputs": [],
   "source": [
    "vectorpath = \"/Users/wzx/Downloads/symbolvectors.txt\" #os.path.join(kwarg[\"root\"], \"raw\",\"symbolvectors.txt\")\n",
    "def ReadVector(file):\n",
    "    Symbol2Vector = {}\n",
    "    with open(file, \"r\") as VectorFile:\n",
    "        VectorLine = VectorFile.readlines()\n",
    "        for Vector in VectorLine:\n",
    "            Vectorid = int(Vector.split(\" \")[0])\n",
    "            vector = []\n",
    "            for num in Vector.split(\" \")[1:]:\n",
    "                vector.append(float(num))\n",
    "            Symbol2Vector[Vectorid] = vector\n",
    "    return Symbol2Vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "humanitarian-waste",
   "metadata": {},
   "outputs": [],
   "source": [
    "def ReadVector(file):\n",
    "    Symbol2Vector = {}\n",
    "    with open(file, \"r\") as VectorFile:\n",
    "        VectorLine = VectorFile.readlines()\n",
    "        for Vector in VectorLine:\n",
    "            Vectorid = int(Vector.split(\" \")[0])\n",
    "            vector = []\n",
    "            for num in Vector.split(\" \")[1:]:\n",
    "                vector.append(float(num))\n",
    "            Symbol2Vector[Vectorid] = vector\n",
    "    return Symbol2Vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "formed-meaning",
   "metadata": {},
   "outputs": [],
   "source": [
    "def ReadSymboljson(file):\n",
    "    di={}\n",
    "    with open(file, 'r', encoding='utf8') as fp:\n",
    "        json_data = json.load(fp)\n",
    "        for filename in json_data:\n",
    "            di[filename['name']]=[]\n",
    "            for symbol in filename['symbol']:\n",
    "                di[filename['name']].append(symbol)\n",
    "    return di\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "green-twist",
   "metadata": {},
   "outputs": [],
   "source": [
    "qqq = ReadVector(vectorpath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "excited-thirty",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'alias.c': 0,\n",
       " 'alias.h': 1,\n",
       " 'bashansi.h': 2,\n",
       " 'bashtypes.h': 3,\n",
       " 'builtins/mkbuiltins.c': 4,\n",
       " 'command.h': 5,\n",
       " 'config-bot.h': 6,\n",
       " 'config.h': 7,\n",
       " 'config-top.h': 8,\n",
       " 'externs.h': 9,\n",
       " 'general.h': 10,\n",
       " 'hashlib.c': 11,\n",
       " 'hashlib.h': 12,\n",
       " 'include/chartypes.h': 13,\n",
       " 'include/stdc.h': 14,\n",
       " 'lib/intl/relocatable.c': 15,\n",
       " 'lib/malloc/imalloc.h': 16,\n",
       " 'lib/malloc/xmalloc.c': 17,\n",
       " 'lib/readline/chardefs.h': 18,\n",
       " 'lib/readline/complete.c': 19,\n",
       " 'lib/readline/funmap.c': 20,\n",
       " 'lib/readline/histlib.h': 21,\n",
       " 'lib/readline/rldefs.h': 22,\n",
       " 'lib/readline/tilde.c': 23,\n",
       " 'lib/readline/vi_mode.c': 24,\n",
       " 'lib/readline/xmalloc.h': 25,\n",
       " 'lib/sh/mbschr.c': 26,\n",
       " 'lib/sh/stringvec.c': 27,\n",
       " 'lib/tilde/tilde.c': 28,\n",
       " 'pcomplete.c': 29,\n",
       " 'pcomplete.h': 30,\n",
       " 'xmalloc.c': 31,\n",
       " 'xmalloc.h': 32,\n",
       " 'array.c': 33,\n",
       " 'arrayfunc.h': 34,\n",
       " 'array.h': 35,\n",
       " 'assoc.h': 36,\n",
       " 'bashjmp.h': 37,\n",
       " 'builtins/common.h': 38,\n",
       " 'conftypes.h': 39,\n",
       " 'dispose_cmd.h': 40,\n",
       " 'error.h': 41,\n",
       " 'include/maxpath.h': 42,\n",
       " 'include/ocache.h': 43,\n",
       " 'include/posixjmp.h': 44,\n",
       " 'lib/glob/smatch.c': 45,\n",
       " 'lib/glob/xmbsrtowcs.c': 46,\n",
       " 'lib/readline/rlshell.h': 47,\n",
       " 'lib/readline/shell.c': 48,\n",
       " 'lib/sh/casemod.c': 49,\n",
       " 'lib/sh/itos.c': 50,\n",
       " 'lib/sh/shquote.c': 51,\n",
       " 'make_cmd.c': 52,\n",
       " 'make_cmd.h': 53,\n",
       " 'pathnames.h': 54,\n",
       " 'quit.h': 55,\n",
       " 'shell.h': 56,\n",
       " 'sig.h': 57,\n",
       " 'subst.c': 58,\n",
       " 'subst.h': 59,\n",
       " 'syntax.h': 60,\n",
       " 'unwind_prot.h': 61,\n",
       " 'variables.h': 62,\n",
       " 'arrayfunc.c': 63,\n",
       " 'assoc.c': 64,\n",
       " 'bashintl.h': 65,\n",
       " 'bashline.c': 66,\n",
       " 'builtins/break.c': 67,\n",
       " 'builtins/builtin.c': 68,\n",
       " 'builtins/cd.c': 69,\n",
       " 'builtins/common.c': 70,\n",
       " 'builtins/declare.c': 71,\n",
       " 'builtins/evalfile.c': 72,\n",
       " 'builtins/evalstring.c': 73,\n",
       " 'builtins/exit.c': 74,\n",
       " 'builtins/fg_bg.c': 75,\n",
       " 'builtins/getopts.c': 76,\n",
       " 'builtins/hash.c': 77,\n",
       " 'builtins/return.c': 78,\n",
       " 'builtins/setattr.c': 79,\n",
       " 'builtins/source.c': 80,\n",
       " 'builtins/test.c': 81,\n",
       " 'builtins/type.c': 82,\n",
       " 'dispose_cmd.c': 83,\n",
       " 'error.c': 84,\n",
       " 'eval.c': 85,\n",
       " 'execute_cmd.c': 86,\n",
       " 'expr.c': 87,\n",
       " 'general.c': 88,\n",
       " 'include/gettext.h': 89,\n",
       " 'include/shmbchar.h': 90,\n",
       " 'include/shmbutil.h': 91,\n",
       " 'jobs.c': 92,\n",
       " 'nojobs.c': 93,\n",
       " 'pathexp.c': 94,\n",
       " 'pathexp.h': 95,\n",
       " 'redir.c': 96,\n",
       " 'shell.c': 97,\n",
       " 'sig.c': 98,\n",
       " 'stringlib.c': 99,\n",
       " 'trap.c': 100,\n",
       " 'variables.c': 101,\n",
       " 'y.tab.c': 102,\n",
       " 'bashhist.c': 103,\n",
       " 'bashhist.h': 104,\n",
       " 'bashline.h': 105,\n",
       " 'builtins/fc.c': 106,\n",
       " 'builtins/history.c': 107,\n",
       " 'builtins/shopt.c': 108,\n",
       " 'flags.c': 109,\n",
       " 'flags.h': 110,\n",
       " 'include/filecntl.h': 111,\n",
       " 'include/posixstat.h': 112,\n",
       " 'input.h': 113,\n",
       " 'lib/glob/glob.c': 114,\n",
       " 'lib/glob/glob.h': 115,\n",
       " 'lib/glob/strmatch.c': 116,\n",
       " 'lib/glob/strmatch.h': 117,\n",
       " 'lib/readline/histexpand.c': 118,\n",
       " 'lib/readline/histfile.c': 119,\n",
       " 'lib/readline/history.c': 120,\n",
       " 'lib/readline/history.h': 121,\n",
       " 'lib/readline/histsearch.c': 122,\n",
       " 'lib/readline/readline.c': 123,\n",
       " 'lib/readline/readline.h': 124,\n",
       " 'lib/readline/rlstdc.h': 125,\n",
       " 'lib/readline/rltypedefs.h': 126,\n",
       " 'lib/sh/strftime.c': 127,\n",
       " 'lib/sh/unicode.c': 128,\n",
       " 'parser.h': 129,\n",
       " 'lib/intl/libgnuintl.h': 130,\n",
       " 'lib/readline/posixjmp.h': 131,\n",
       " 'bracecomp.c': 132,\n",
       " 'builtins/alias.c': 133,\n",
       " 'builtins/builtins.c': 134,\n",
       " 'builtins/echo.c': 135,\n",
       " 'builtins.h': 136,\n",
       " 'builtins/kill.c': 137,\n",
       " 'builtins/set.c': 138,\n",
       " 'builtins/trap.c': 139,\n",
       " 'builtins/ulimit.c': 140,\n",
       " 'execute_cmd.h': 141,\n",
       " 'findcmd.c': 142,\n",
       " 'findcmd.h': 143,\n",
       " 'lib/readline/bind.c': 144,\n",
       " 'lib/readline/compat.c': 145,\n",
       " 'lib/readline/display.c': 146,\n",
       " 'lib/readline/emacs_keymap.c': 147,\n",
       " 'lib/readline/input.c': 148,\n",
       " 'lib/readline/keymaps.c': 149,\n",
       " 'lib/readline/keymaps.h': 150,\n",
       " 'lib/readline/kill.c': 151,\n",
       " 'lib/readline/macro.c': 152,\n",
       " 'lib/readline/misc.c': 153,\n",
       " 'lib/readline/rlconf.h': 154,\n",
       " 'lib/readline/rltty.c': 155,\n",
       " 'lib/readline/tcap.h': 156,\n",
       " 'lib/readline/terminal.c': 157,\n",
       " 'lib/readline/text.c': 158,\n",
       " 'lib/readline/tilde.h': 159,\n",
       " 'lib/readline/undo.c': 160,\n",
       " 'lib/readline/util.c': 161,\n",
       " 'lib/readline/vi_keymap.c': 162,\n",
       " 'lib/sh/fnxform.c': 163,\n",
       " 'lib/sh/makepath.c': 164,\n",
       " 'lib/sh/pathcanon.c': 165,\n",
       " 'lib/sh/pathphys.c': 166,\n",
       " 'lib/sh/shmatch.c': 167,\n",
       " 'lib/sh/spell.c': 168,\n",
       " 'lib/termcap/termcap.c': 169,\n",
       " 'pcomplib.c': 170,\n",
       " 'support/bashversion.c': 171,\n",
       " 'syntax.c': 172,\n",
       " 'version.c': 173,\n",
       " 'braces.c': 174,\n",
       " 'lib/sh/strstr.c': 175,\n",
       " 'lib/sh/strtoimax.c': 176,\n",
       " 'builtins/bashgetopt.c': 177,\n",
       " 'builtins/bashgetopt.h': 178,\n",
       " 'builtins/bind.c': 179,\n",
       " 'builtins/enable.c': 180,\n",
       " 'unwind_prot.c': 181,\n",
       " 'builtins/builtext.h': 182,\n",
       " 'builtins/caller.c': 183,\n",
       " 'builtins/colon.c': 184,\n",
       " 'builtins/command.c': 185,\n",
       " 'builtins/complete.c': 186,\n",
       " 'builtins/eval.c': 187,\n",
       " 'builtins/exec.c': 188,\n",
       " 'builtins/help.c': 189,\n",
       " 'builtins/jobs.c': 190,\n",
       " 'builtins/let.c': 191,\n",
       " 'builtins/mapfile.c': 192,\n",
       " 'builtins/printf.c': 193,\n",
       " 'builtins/pushd.c': 194,\n",
       " 'builtins/read.c': 195,\n",
       " 'builtins/shift.c': 196,\n",
       " 'builtins/suspend.c': 197,\n",
       " 'builtins/times.c': 198,\n",
       " 'builtins/umask.c': 199,\n",
       " 'builtins/wait.c': 200,\n",
       " 'include/posixdir.h': 201,\n",
       " 'lib/tilde/tilde.h': 202,\n",
       " 'copy_cmd.c': 203,\n",
       " 'include/posixwait.h': 204,\n",
       " 'input.c': 205,\n",
       " 'jobs.h': 206,\n",
       " 'lib/intl/dcigettext.c': 207,\n",
       " 'lib/sh/fpurge.c': 208,\n",
       " 'lib/sh/strcasestr.c': 209,\n",
       " 'siglist.h': 210,\n",
       " 'trap.h': 211,\n",
       " 'lib/sh/stringlist.c': 212,\n",
       " 'print_cmd.c': 213,\n",
       " 'lib/sh/strtrans.c': 214,\n",
       " 'include/typemax.h': 215,\n",
       " 'lib/sh/zmapfd.c': 216,\n",
       " 'lib/malloc/malloc.c': 217,\n",
       " 'lib/readline/xfree.c': 218,\n",
       " 'lib/sh/zcatfd.c': 219,\n",
       " 'redir.h': 220,\n",
       " 'y.tab.h': 221,\n",
       " 'lib/sh/tmpfile.c': 222,\n",
       " 'builtins/getopt.c': 223,\n",
       " 'builtins/getopt.h': 224,\n",
       " 'include/memalloc.h': 225,\n",
       " 'hashcmd.c': 226,\n",
       " 'hashcmd.h': 227,\n",
       " 'lib/sh/zgetline.c': 228,\n",
       " 'lib/sh/zread.c': 229,\n",
       " 'include/posixtime.h': 230,\n",
       " 'lib/readline/rlmbutil.h': 231,\n",
       " 'lib/sh/strtoumax.c': 232,\n",
       " 'mailcheck.c': 233,\n",
       " 'builtins/psize.c': 234,\n",
       " 'include/shtty.h': 235,\n",
       " 'lib/readline/signals.c': 236,\n",
       " 'lib/sh/input_avail.c': 237,\n",
       " 'lib/sh/shtty.c': 238,\n",
       " 'lib/sh/uconvert.c': 239,\n",
       " 'lib/sh/ufuncs.c': 240,\n",
       " 'version.h': 241,\n",
       " 'test.c': 242,\n",
       " 'test.h': 243,\n",
       " 'lib/sh/timeval.c': 244,\n",
       " 'builtins/pipesize.h': 245,\n",
       " 'lib/sh/oslib.c': 246,\n",
       " 'lib/readline/posixstat.h': 247,\n",
       " 'list.c': 248,\n",
       " 'lib/sh/fmtumax.c': 249,\n",
       " 'lib/sh/eaccess.c': 250,\n",
       " 'lib/intl/loadmsgcat.c': 251,\n",
       " 'lib/intl/localealias.c': 252,\n",
       " 'lib/readline/posixdir.h': 253,\n",
       " 'include/posixselect.h': 254,\n",
       " 'lib/readline/posixselect.h': 255,\n",
       " 'lib/sh/shmbchar.c': 256,\n",
       " 'lib/sh/winsize.c': 257,\n",
       " 'lib/glob/collsyms.h': 258,\n",
       " 'lib/glob/glob_loop.c': 259,\n",
       " 'lib/glob/gmisc.c': 260,\n",
       " 'lib/glob/sm_loop.c': 261,\n",
       " 'lib/intl/l10nflist.c': 262,\n",
       " 'lib/sh/strchrnul.c': 263,\n",
       " 'lib/intl/bindtextdom.c': 264,\n",
       " 'lib/intl/gettextP.h': 265,\n",
       " 'lib/intl/gmo.h': 266,\n",
       " 'lib/intl/loadinfo.h': 267,\n",
       " 'lib/intl/os2compat.c': 268,\n",
       " 'lib/intl/plural-exp.h': 269,\n",
       " 'lib/intl/textdomain.c': 270,\n",
       " 'lib/intl/dcgettext.c': 271,\n",
       " 'lib/intl/dcngettext.c': 272,\n",
       " 'lib/intl/dgettext.c': 273,\n",
       " 'lib/intl/gettext.c': 274,\n",
       " 'lib/intl/eval-plural.h': 275,\n",
       " 'lib/intl/finddomain.c': 276,\n",
       " 'lib/intl/hash-string.h': 277,\n",
       " 'lib/intl/localcharset.c': 278,\n",
       " 'lib/intl/localename.c': 279,\n",
       " 'lib/intl/log.c': 280,\n",
       " 'lib/sh/getenv.c': 281,\n",
       " 'lib/intl/dngettext.c': 282,\n",
       " 'lib/intl/ngettext.c': 283,\n",
       " 'lib/intl/explodename.c': 284,\n",
       " 'lib/intl/intl-compat.c': 285,\n",
       " 'lib/intl/localcharset.h': 286,\n",
       " 'lib/intl/relocatable.h': 287,\n",
       " 'lib/intl/plural.c': 288,\n",
       " 'lib/intl/plural-exp.c': 289,\n",
       " 'lib/malloc/alloca.c': 290,\n",
       " 'lib/malloc/shmalloc.h': 291,\n",
       " 'lib/malloc/stats.c': 292,\n",
       " 'lib/malloc/table.c': 293,\n",
       " 'lib/malloc/table.h': 294,\n",
       " 'lib/malloc/trace.c': 295,\n",
       " 'lib/malloc/watch.c': 296,\n",
       " 'lib/readline/xmalloc.c': 297,\n",
       " 'lib/readline/isearch.c': 298,\n",
       " 'lib/readline/mbutil.c': 299,\n",
       " 'lib/readline/parens.c': 300,\n",
       " 'lib/readline/rlprivate.h': 301,\n",
       " 'lib/readline/callback.c': 302,\n",
       " 'lib/readline/search.c': 303,\n",
       " 'lib/termcap/tparam.c': 304,\n",
       " 'lib/readline/nls.c': 305,\n",
       " 'lib/readline/savestring.c': 306,\n",
       " 'lib/readline/rltty.h': 307,\n",
       " 'lib/readline/rlwinsize.h': 308,\n",
       " 'lib/sh/clktck.c': 309,\n",
       " 'lib/sh/clock.c': 310,\n",
       " 'lib/sh/dprintf.c': 311,\n",
       " 'lib/sh/fmtullong.c': 312,\n",
       " 'lib/sh/fmtulong.c': 313,\n",
       " 'locale.c': 314,\n",
       " 'lib/sh/getcwd.c': 315,\n",
       " 'support/printenv.c': 316,\n",
       " 'lib/sh/inet_aton.c': 317,\n",
       " 'lib/sh/mailstat.c': 318,\n",
       " 'lib/sh/mbscasecmp.c': 319,\n",
       " 'lib/sh/mbscmp.c': 320,\n",
       " 'lib/sh/mktime.c': 321,\n",
       " 'lib/sh/netconn.c': 322,\n",
       " 'lib/sh/netopen.c': 323,\n",
       " 'lib/sh/rename.c': 324,\n",
       " 'lib/sh/setlinebuf.c': 325,\n",
       " 'lib/sh/snprintf.c': 326,\n",
       " 'lib/sh/strcasecmp.c': 327,\n",
       " 'lib/sh/strerror.c': 328,\n",
       " 'lib/sh/strnlen.c': 329,\n",
       " 'lib/sh/strpbrk.c': 330,\n",
       " 'lib/sh/strtod.c': 331,\n",
       " 'lib/sh/strtol.c': 332,\n",
       " 'lib/sh/strtoll.c': 333,\n",
       " 'lib/sh/strtoul.c': 334,\n",
       " 'lib/sh/strtoull.c': 335,\n",
       " 'lib/sh/times.c': 336,\n",
       " 'lib/sh/vprint.c': 337,\n",
       " 'lib/sh/wcsdup.c': 338,\n",
       " 'lib/sh/wcswidth.c': 339,\n",
       " 'lib/sh/zwrite.c': 340,\n",
       " 'lib/termcap/ltcap.h': 341,\n",
       " 'lib/tilde/shell.c': 342,\n",
       " 'mailcheck.h': 343,\n",
       " 'mksyntax.c': 344,\n",
       " 'support/mksignames.c': 345,\n",
       " 'support/signames.c': 346,\n",
       " 'signames.h': 347,\n",
       " 'siglist.c': 348,\n",
       " 'support/man2html.c': 349,\n",
       " 'support/recho.c': 350,\n",
       " 'support/zecho.c': 351,\n",
       " 'patchlevel.h': 352}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.dic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "olympic-albert",
   "metadata": {},
   "outputs": [],
   "source": [
    "recdic = dict(zip(dataset.dic.values(), dataset.dic.keys()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "saved-october",
   "metadata": {},
   "outputs": [],
   "source": [
    "filesymboljson= os.path.join(kwarg[\"root\"], \"raw\",\"filedefsymbol.json\")\n",
    "q = ReadSymboljson(filesymboljson)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "finite-scout",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alias.c\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[9606,\n",
       " 9671,\n",
       " 9670,\n",
       " 9634,\n",
       " 9609,\n",
       " 9633,\n",
       " 9608,\n",
       " 9632,\n",
       " 9595,\n",
       " 9631,\n",
       " 9594,\n",
       " 9625,\n",
       " 9624,\n",
       " 9607,\n",
       " 9623,\n",
       " 9622,\n",
       " 9621,\n",
       " 9620,\n",
       " 9614,\n",
       " 9605,\n",
       " 9604,\n",
       " 9603,\n",
       " 9601,\n",
       " 9618,\n",
       " 9602,\n",
       " 9619,\n",
       " 9626,\n",
       " 9589,\n",
       " 9668,\n",
       " 9627,\n",
       " 9590,\n",
       " 9669,\n",
       " 9628,\n",
       " 9591,\n",
       " 9615,\n",
       " 9616,\n",
       " 9629,\n",
       " 9592,\n",
       " 9617,\n",
       " 9630,\n",
       " 9593,\n",
       " 9610,\n",
       " 9635,\n",
       " 9636,\n",
       " 9637,\n",
       " 9596,\n",
       " 9638,\n",
       " 9597,\n",
       " 9639,\n",
       " 9640,\n",
       " 9641,\n",
       " 9611,\n",
       " 9642,\n",
       " 9643,\n",
       " 9644,\n",
       " 9645,\n",
       " 9612,\n",
       " 9646,\n",
       " 9647,\n",
       " 9648,\n",
       " 9649,\n",
       " 9650,\n",
       " 9651,\n",
       " 9613,\n",
       " 9652,\n",
       " 9653,\n",
       " 9654,\n",
       " 9598,\n",
       " 9655,\n",
       " 9656,\n",
       " 9657,\n",
       " 9658,\n",
       " 9659,\n",
       " 9660,\n",
       " 9661,\n",
       " 9662,\n",
       " 9663,\n",
       " 9664,\n",
       " 9665,\n",
       " 9666,\n",
       " 9667]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(recdic[0])\n",
    "q[recdic[0]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "about-nowhere",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "300"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "value=list(qqq.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "interesting-retail",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1160"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(value[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "occupied-graduation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>1150</th>\n",
       "      <th>1151</th>\n",
       "      <th>1152</th>\n",
       "      <th>1153</th>\n",
       "      <th>1154</th>\n",
       "      <th>1155</th>\n",
       "      <th>1156</th>\n",
       "      <th>1157</th>\n",
       "      <th>1158</th>\n",
       "      <th>1159</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.059064</td>\n",
       "      <td>0.004270</td>\n",
       "      <td>0.068029</td>\n",
       "      <td>0.085352</td>\n",
       "      <td>0.005009</td>\n",
       "      <td>0.039716</td>\n",
       "      <td>0.060315</td>\n",
       "      <td>0.036177</td>\n",
       "      <td>0.001256</td>\n",
       "      <td>...</td>\n",
       "      <td>0.009422</td>\n",
       "      <td>0.005298</td>\n",
       "      <td>0.070349</td>\n",
       "      <td>0.045339</td>\n",
       "      <td>0.038657</td>\n",
       "      <td>0.088212</td>\n",
       "      <td>0.039538</td>\n",
       "      <td>0.045790</td>\n",
       "      <td>0.012673</td>\n",
       "      <td>0.059342</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.059064</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.077693</td>\n",
       "      <td>0.294807</td>\n",
       "      <td>0.091430</td>\n",
       "      <td>0.337997</td>\n",
       "      <td>0.478794</td>\n",
       "      <td>0.439387</td>\n",
       "      <td>0.491918</td>\n",
       "      <td>0.555327</td>\n",
       "      <td>...</td>\n",
       "      <td>0.405459</td>\n",
       "      <td>0.264322</td>\n",
       "      <td>0.218779</td>\n",
       "      <td>0.383507</td>\n",
       "      <td>0.529830</td>\n",
       "      <td>0.391600</td>\n",
       "      <td>0.463067</td>\n",
       "      <td>0.270247</td>\n",
       "      <td>0.089798</td>\n",
       "      <td>0.711004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.004270</td>\n",
       "      <td>0.077693</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.126786</td>\n",
       "      <td>0.109063</td>\n",
       "      <td>0.180276</td>\n",
       "      <td>0.027738</td>\n",
       "      <td>0.191538</td>\n",
       "      <td>0.096924</td>\n",
       "      <td>0.089351</td>\n",
       "      <td>...</td>\n",
       "      <td>0.318447</td>\n",
       "      <td>0.258964</td>\n",
       "      <td>0.186660</td>\n",
       "      <td>0.389741</td>\n",
       "      <td>0.189241</td>\n",
       "      <td>0.161614</td>\n",
       "      <td>0.048394</td>\n",
       "      <td>0.252377</td>\n",
       "      <td>0.275051</td>\n",
       "      <td>0.113410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.068029</td>\n",
       "      <td>0.294807</td>\n",
       "      <td>0.126786</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.259657</td>\n",
       "      <td>0.571874</td>\n",
       "      <td>0.317886</td>\n",
       "      <td>0.285163</td>\n",
       "      <td>0.128361</td>\n",
       "      <td>0.156125</td>\n",
       "      <td>...</td>\n",
       "      <td>0.488042</td>\n",
       "      <td>0.359850</td>\n",
       "      <td>0.263919</td>\n",
       "      <td>0.434989</td>\n",
       "      <td>0.440703</td>\n",
       "      <td>0.030336</td>\n",
       "      <td>0.320276</td>\n",
       "      <td>0.130965</td>\n",
       "      <td>0.137983</td>\n",
       "      <td>0.435818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.085352</td>\n",
       "      <td>0.091430</td>\n",
       "      <td>0.109063</td>\n",
       "      <td>0.259657</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.240268</td>\n",
       "      <td>0.137877</td>\n",
       "      <td>0.095638</td>\n",
       "      <td>0.063211</td>\n",
       "      <td>0.036920</td>\n",
       "      <td>...</td>\n",
       "      <td>0.100144</td>\n",
       "      <td>0.012187</td>\n",
       "      <td>0.106914</td>\n",
       "      <td>0.036487</td>\n",
       "      <td>0.008100</td>\n",
       "      <td>0.014560</td>\n",
       "      <td>0.132649</td>\n",
       "      <td>0.087322</td>\n",
       "      <td>0.325120</td>\n",
       "      <td>0.004803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1155</th>\n",
       "      <td>0.088212</td>\n",
       "      <td>0.391600</td>\n",
       "      <td>0.161614</td>\n",
       "      <td>0.030336</td>\n",
       "      <td>0.014560</td>\n",
       "      <td>0.192436</td>\n",
       "      <td>0.024372</td>\n",
       "      <td>0.117045</td>\n",
       "      <td>0.262193</td>\n",
       "      <td>0.204994</td>\n",
       "      <td>...</td>\n",
       "      <td>0.342659</td>\n",
       "      <td>0.067033</td>\n",
       "      <td>0.147970</td>\n",
       "      <td>0.222644</td>\n",
       "      <td>0.300761</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.193975</td>\n",
       "      <td>0.477112</td>\n",
       "      <td>0.141367</td>\n",
       "      <td>0.377308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1156</th>\n",
       "      <td>0.039538</td>\n",
       "      <td>0.463067</td>\n",
       "      <td>0.048394</td>\n",
       "      <td>0.320276</td>\n",
       "      <td>0.132649</td>\n",
       "      <td>0.323820</td>\n",
       "      <td>0.430543</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.330710</td>\n",
       "      <td>0.219213</td>\n",
       "      <td>...</td>\n",
       "      <td>0.380707</td>\n",
       "      <td>0.226100</td>\n",
       "      <td>0.398770</td>\n",
       "      <td>0.289582</td>\n",
       "      <td>0.410427</td>\n",
       "      <td>0.193975</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.381073</td>\n",
       "      <td>0.152622</td>\n",
       "      <td>0.485475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1157</th>\n",
       "      <td>0.045790</td>\n",
       "      <td>0.270247</td>\n",
       "      <td>0.252377</td>\n",
       "      <td>0.130965</td>\n",
       "      <td>0.087322</td>\n",
       "      <td>0.188967</td>\n",
       "      <td>0.125836</td>\n",
       "      <td>0.184207</td>\n",
       "      <td>0.310081</td>\n",
       "      <td>0.258113</td>\n",
       "      <td>...</td>\n",
       "      <td>0.397713</td>\n",
       "      <td>0.236826</td>\n",
       "      <td>0.190058</td>\n",
       "      <td>0.348684</td>\n",
       "      <td>0.254701</td>\n",
       "      <td>0.477112</td>\n",
       "      <td>0.381073</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.199637</td>\n",
       "      <td>0.440301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1158</th>\n",
       "      <td>0.012673</td>\n",
       "      <td>0.089798</td>\n",
       "      <td>0.275051</td>\n",
       "      <td>0.137983</td>\n",
       "      <td>0.325120</td>\n",
       "      <td>0.067681</td>\n",
       "      <td>0.125626</td>\n",
       "      <td>0.269321</td>\n",
       "      <td>0.153803</td>\n",
       "      <td>0.166500</td>\n",
       "      <td>...</td>\n",
       "      <td>0.202675</td>\n",
       "      <td>0.321884</td>\n",
       "      <td>0.296698</td>\n",
       "      <td>0.409516</td>\n",
       "      <td>0.200808</td>\n",
       "      <td>0.141367</td>\n",
       "      <td>0.152622</td>\n",
       "      <td>0.199637</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.261412</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1159</th>\n",
       "      <td>0.059342</td>\n",
       "      <td>0.711004</td>\n",
       "      <td>0.113410</td>\n",
       "      <td>0.435818</td>\n",
       "      <td>0.004803</td>\n",
       "      <td>0.326002</td>\n",
       "      <td>0.471091</td>\n",
       "      <td>0.351979</td>\n",
       "      <td>0.483336</td>\n",
       "      <td>0.547555</td>\n",
       "      <td>...</td>\n",
       "      <td>0.672761</td>\n",
       "      <td>0.529515</td>\n",
       "      <td>0.256736</td>\n",
       "      <td>0.747498</td>\n",
       "      <td>0.576465</td>\n",
       "      <td>0.377308</td>\n",
       "      <td>0.485475</td>\n",
       "      <td>0.440301</td>\n",
       "      <td>0.261412</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1160 rows × 1160 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6     \\\n",
       "0     1.000000  0.059064  0.004270  0.068029  0.085352  0.005009  0.039716   \n",
       "1     0.059064  1.000000  0.077693  0.294807  0.091430  0.337997  0.478794   \n",
       "2     0.004270  0.077693  1.000000  0.126786  0.109063  0.180276  0.027738   \n",
       "3     0.068029  0.294807  0.126786  1.000000  0.259657  0.571874  0.317886   \n",
       "4     0.085352  0.091430  0.109063  0.259657  1.000000  0.240268  0.137877   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "1155  0.088212  0.391600  0.161614  0.030336  0.014560  0.192436  0.024372   \n",
       "1156  0.039538  0.463067  0.048394  0.320276  0.132649  0.323820  0.430543   \n",
       "1157  0.045790  0.270247  0.252377  0.130965  0.087322  0.188967  0.125836   \n",
       "1158  0.012673  0.089798  0.275051  0.137983  0.325120  0.067681  0.125626   \n",
       "1159  0.059342  0.711004  0.113410  0.435818  0.004803  0.326002  0.471091   \n",
       "\n",
       "          7         8         9     ...      1150      1151      1152  \\\n",
       "0     0.060315  0.036177  0.001256  ...  0.009422  0.005298  0.070349   \n",
       "1     0.439387  0.491918  0.555327  ...  0.405459  0.264322  0.218779   \n",
       "2     0.191538  0.096924  0.089351  ...  0.318447  0.258964  0.186660   \n",
       "3     0.285163  0.128361  0.156125  ...  0.488042  0.359850  0.263919   \n",
       "4     0.095638  0.063211  0.036920  ...  0.100144  0.012187  0.106914   \n",
       "...        ...       ...       ...  ...       ...       ...       ...   \n",
       "1155  0.117045  0.262193  0.204994  ...  0.342659  0.067033  0.147970   \n",
       "1156  0.189671  0.330710  0.219213  ...  0.380707  0.226100  0.398770   \n",
       "1157  0.184207  0.310081  0.258113  ...  0.397713  0.236826  0.190058   \n",
       "1158  0.269321  0.153803  0.166500  ...  0.202675  0.321884  0.296698   \n",
       "1159  0.351979  0.483336  0.547555  ...  0.672761  0.529515  0.256736   \n",
       "\n",
       "          1153      1154      1155      1156      1157      1158      1159  \n",
       "0     0.045339  0.038657  0.088212  0.039538  0.045790  0.012673  0.059342  \n",
       "1     0.383507  0.529830  0.391600  0.463067  0.270247  0.089798  0.711004  \n",
       "2     0.389741  0.189241  0.161614  0.048394  0.252377  0.275051  0.113410  \n",
       "3     0.434989  0.440703  0.030336  0.320276  0.130965  0.137983  0.435818  \n",
       "4     0.036487  0.008100  0.014560  0.132649  0.087322  0.325120  0.004803  \n",
       "...        ...       ...       ...       ...       ...       ...       ...  \n",
       "1155  0.222644  0.300761  1.000000  0.193975  0.477112  0.141367  0.377308  \n",
       "1156  0.289582  0.410427  0.193975  1.000000  0.381073  0.152622  0.485475  \n",
       "1157  0.348684  0.254701  0.477112  0.381073  1.000000  0.199637  0.440301  \n",
       "1158  0.409516  0.200808  0.141367  0.152622  0.199637  1.000000  0.261412  \n",
       "1159  0.747498  0.576465  0.377308  0.485475  0.440301  0.261412  1.000000  \n",
       "\n",
       "[1160 rows x 1160 columns]"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = cosine_similarity(value)\n",
    "mm = np.maximum(m, -m)\n",
    "mmm = pd.DataFrame(mm)\n",
    "mmm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "supported-redhead",
   "metadata": {},
   "outputs": [],
   "source": [
    "mmmm = mm.reshape(len(mm)*len(mm),1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "marine-phase",
   "metadata": {},
   "outputs": [],
   "source": [
    "t=getmaxIndex(mmmm,len(mm)+20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "featured-director",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[794125,\n",
       " 795284,\n",
       " 65025,\n",
       " 75456,\n",
       " 1059999,\n",
       " 1066953,\n",
       " 658333,\n",
       " 711647,\n",
       " 1333990,\n",
       " 1335149,\n",
       " 326242,\n",
       " 327401,\n",
       " 1288711,\n",
       " 1289870,\n",
       " 24391,\n",
       " 35981,\n",
       " 261226,\n",
       " 262385,\n",
       " 756977,\n",
       " 762772]"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q = t[-20:]\n",
    "q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "moderate-sender",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.99581289])"
      ]
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mmmm[794125]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "loose-protocol",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.07000031])"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mmmm[785875]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "parliamentary-richards",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "index 5506 is out of bounds for axis 0 with size 1160",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-158-65265243b074>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmm\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m5506\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m5507\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m: index 5506 is out of bounds for axis 0 with size 1160"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "quiet-april",
   "metadata": {},
   "outputs": [],
   "source": [
    "maxten = q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "thousand-acting",
   "metadata": {},
   "outputs": [],
   "source": [
    "def method(lista):\n",
    "    res = []\n",
    "    for idx in lista:\n",
    "        x = int(idx/len(mm))\n",
    "        y = idx%len(mm)\n",
    "        res.append([key[x],key[y]])\n",
    "    return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "embedded-connecticut",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[5506, 5507],\n",
       " [5507, 5506],\n",
       " [4274, 4293],\n",
       " [4293, 4274],\n",
       " [4699, 4689],\n",
       " [4689, 4699],\n",
       " [9307, 9305],\n",
       " [9305, 9307],\n",
       " [9238, 9237],\n",
       " [9237, 9238],\n",
       " [4280, 4281],\n",
       " [4281, 4280],\n",
       " [5481, 5482],\n",
       " [5482, 5481],\n",
       " [8597, 4820],\n",
       " [4820, 8597],\n",
       " [22337, 22336],\n",
       " [22336, 22337],\n",
       " [5479, 5480],\n",
       " [5480, 5479]]"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "method(maxten)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "fallen-estimate",
   "metadata": {},
   "outputs": [],
   "source": [
    "key=list(qqq.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "dynamic-light",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.99581289])"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mmmm[794125]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "id": "generic-documentation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "685"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "794125%1160"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "strong-directive",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "684.5905172413793"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "794125/1160"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "id": "martial-tract",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5506"
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mm[684,685]\n",
    "key[684]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "forbidden-processor",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查看每个符号最相似的前十个符号\n",
    "# 返回格式\n",
    "'''\n",
    "[\n",
    "    {\n",
    "        sbymold_id = 111\n",
    "        similarity = [\n",
    "\n",
    "    ]\n",
    "    },\n",
    "\n",
    "    {\n",
    "    \n",
    "    }\n",
    "    ...\n",
    "]\n",
    "\n",
    "'''\n",
    "\n",
    "symboldict = {}\n",
    "caiyang = 11\n",
    "\n",
    "for i in range(len(key)):\n",
    "    similarity = []\n",
    "    similaritymetric = []\n",
    "    a=getmaxIndex(m[i],caiyang)\n",
    "    for symbolid in a:\n",
    "        similarity.append(key[symbolid])\n",
    "        similaritymetric.append(m[i][symbolid])\n",
    "    symboldict[key[i]] = [similarity,similaritymetric]\n",
    "    \n",
    "\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "active-embassy",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = \"similarity.json\"\n",
    "with open(path,\"w\") as fp:\n",
    "    fp.write(str(symboldict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "handled-signal",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3707,\n",
       " 19933,\n",
       " 2868,\n",
       " 7119,\n",
       " 2842,\n",
       " 4755,\n",
       " 4756,\n",
       " 4589,\n",
       " 4759,\n",
       " 7106,\n",
       " 5477,\n",
       " 5560,\n",
       " 7939,\n",
       " 4141,\n",
       " 7107,\n",
       " 7108,\n",
       " 3705,\n",
       " 4104,\n",
       " 4727,\n",
       " 8492,\n",
       " 8493,\n",
       " 4743,\n",
       " 5478,\n",
       " 5561,\n",
       " 4818,\n",
       " 4287,\n",
       " 7114,\n",
       " 19932,\n",
       " 4819,\n",
       " 2917,\n",
       " 4820,\n",
       " 6775,\n",
       " 4563,\n",
       " 2492,\n",
       " 4821,\n",
       " 3116,\n",
       " 4777,\n",
       " 4269,\n",
       " 3706,\n",
       " 3647,\n",
       " 3704,\n",
       " 9263,\n",
       " 4116,\n",
       " 4267,\n",
       " 4561,\n",
       " 4773,\n",
       " 3115,\n",
       " 14162,\n",
       " 4830,\n",
       " 6664,\n",
       " 3702,\n",
       " 6672,\n",
       " 2837,\n",
       " 4117,\n",
       " 3972,\n",
       " 4274,\n",
       " 5509,\n",
       " 7927,\n",
       " 6666,\n",
       " 3877,\n",
       " 2504,\n",
       " 812,\n",
       " 4566,\n",
       " 2870,\n",
       " 4293,\n",
       " 4719,\n",
       " 3860,\n",
       " 3851,\n",
       " 9296,\n",
       " 2855,\n",
       " 817,\n",
       " 4562,\n",
       " 3003,\n",
       " 6811,\n",
       " 4276,\n",
       " 14406,\n",
       " 4826,\n",
       " 3100,\n",
       " 4273,\n",
       " 4843,\n",
       " 2507,\n",
       " 4146,\n",
       " 4580,\n",
       " 2640,\n",
       " 3854,\n",
       " 6810,\n",
       " 2999,\n",
       " 2505,\n",
       " 9576,\n",
       " 2838,\n",
       " 4825,\n",
       " 4581,\n",
       " 4741,\n",
       " 4279,\n",
       " 4837,\n",
       " 2834,\n",
       " 6824,\n",
       " 4152,\n",
       " 3703,\n",
       " 3937,\n",
       " 4571,\n",
       " 5496,\n",
       " 7937,\n",
       " 9591,\n",
       " 9281,\n",
       " 2847,\n",
       " 14408,\n",
       " 3160,\n",
       " 4118,\n",
       " 8503,\n",
       " 7880,\n",
       " 3969,\n",
       " 3165,\n",
       " 14237,\n",
       " 8163,\n",
       " 4824,\n",
       " 4297,\n",
       " 14221,\n",
       " 14409,\n",
       " 3103,\n",
       " 4785,\n",
       " 20087,\n",
       " 4283,\n",
       " 4738,\n",
       " 3162,\n",
       " 4278,\n",
       " 818,\n",
       " 808,\n",
       " 3099,\n",
       " 4579,\n",
       " 7964,\n",
       " 3845,\n",
       " 3662,\n",
       " 3661,\n",
       " 2641,\n",
       " 2682,\n",
       " 7934,\n",
       " 7963,\n",
       " 4058,\n",
       " 4763,\n",
       " 8793,\n",
       " 4584,\n",
       " 4583,\n",
       " 2723,\n",
       " 7782,\n",
       " 16355,\n",
       " 4845,\n",
       " 8517,\n",
       " 8283,\n",
       " 5350,\n",
       " 4101,\n",
       " 4291,\n",
       " 14410,\n",
       " 14164,\n",
       " 4290,\n",
       " 4656,\n",
       " 4299,\n",
       " 4672,\n",
       " 3970,\n",
       " 7425,\n",
       " 8158,\n",
       " 9564,\n",
       " 4077,\n",
       " 4070,\n",
       " 7253,\n",
       " 14161,\n",
       " 7123,\n",
       " 4749,\n",
       " 7875,\n",
       " 8288,\n",
       " 3648,\n",
       " 8287,\n",
       " 2687,\n",
       " 20083,\n",
       " 2835,\n",
       " 8523,\n",
       " 14407,\n",
       " 3932,\n",
       " 4100,\n",
       " 8989,\n",
       " 8290,\n",
       " 4576,\n",
       " 4083,\n",
       " 2664,\n",
       " 8280,\n",
       " 2824,\n",
       " 2722,\n",
       " 5512,\n",
       " 4265,\n",
       " 8794,\n",
       " 7966,\n",
       " 4082,\n",
       " 4673,\n",
       " 20088,\n",
       " 4797,\n",
       " 3885,\n",
       " 2711,\n",
       " 4709,\n",
       " 7949,\n",
       " 3857,\n",
       " 4760,\n",
       " 7256,\n",
       " 5497,\n",
       " 2638,\n",
       " 4713,\n",
       " 10820,\n",
       " 3117,\n",
       " 4060,\n",
       " 3931,\n",
       " 4294,\n",
       " 4782,\n",
       " 4737,\n",
       " 7111,\n",
       " 7127,\n",
       " 5551,\n",
       " 4724,\n",
       " 3504,\n",
       " 12954,\n",
       " 16357,\n",
       " 9577,\n",
       " 4829,\n",
       " 4585,\n",
       " 2707,\n",
       " 3142,\n",
       " 20086,\n",
       " 20085,\n",
       " 2817,\n",
       " 1227,\n",
       " 4582,\n",
       " 5494,\n",
       " 9578,\n",
       " 7881,\n",
       " 8157,\n",
       " 10821,\n",
       " 14414,\n",
       " 8451,\n",
       " 3886,\n",
       " 2846,\n",
       " 7943,\n",
       " 7236,\n",
       " 3978,\n",
       " 3092,\n",
       " 4678,\n",
       " 4712,\n",
       " 9565,\n",
       " 4753,\n",
       " 8505,\n",
       " 7877,\n",
       " 3878,\n",
       " 7998,\n",
       " 4654,\n",
       " 7793,\n",
       " 4721,\n",
       " 16358,\n",
       " 7879,\n",
       " 4757,\n",
       " 5513,\n",
       " 2860,\n",
       " 14165,\n",
       " 14170,\n",
       " 8470,\n",
       " 3879,\n",
       " 5505,\n",
       " 20090,\n",
       " 12955,\n",
       " 8504,\n",
       " 8284,\n",
       " 4842,\n",
       " 8792,\n",
       " 4586,\n",
       " 5585,\n",
       " 7938,\n",
       " 2780,\n",
       " 7268,\n",
       " 4658,\n",
       " 4087,\n",
       " 11821,\n",
       " 3016,\n",
       " 4792,\n",
       " 9758,\n",
       " 4280,\n",
       " 4281,\n",
       " 7792,\n",
       " 7940,\n",
       " 6745,\n",
       " 4559,\n",
       " 8289,\n",
       " 7671,\n",
       " 4103,\n",
       " 14395,\n",
       " 7124,\n",
       " 4063,\n",
       " 4778,\n",
       " 4298,\n",
       " 4275,\n",
       " 4292,\n",
       " 9253,\n",
       " 4059,\n",
       " 8899,\n",
       " 2660,\n",
       " 4725,\n",
       " 4115,\n",
       " 14227,\n",
       " 7260,\n",
       " 2772,\n",
       " 4091,\n",
       " 7257,\n",
       " 3013,\n",
       " 7272,\n",
       " 4761,\n",
       " 4053,\n",
       " 5503,\n",
       " 3971,\n",
       " 4794,\n",
       " 3880,\n",
       " 5348,\n",
       " 20089,\n",
       " 9222,\n",
       " 7986,\n",
       " 7957,\n",
       " 9231,\n",
       " 4664,\n",
       " 4662,\n",
       " 7990,\n",
       " 4088,\n",
       " 2663,\n",
       " 7098,\n",
       " 4564,\n",
       " 3920,\n",
       " 7991,\n",
       " 20091,\n",
       " 9234,\n",
       " 4068,\n",
       " 4666,\n",
       " 14394,\n",
       " 7116,\n",
       " 3056,\n",
       " 4264,\n",
       " 4836,\n",
       " 4827,\n",
       " 4090,\n",
       " 2658,\n",
       " 7876,\n",
       " 1229,\n",
       " 8117,\n",
       " 20084,\n",
       " 7945,\n",
       " 4667,\n",
       " 4074,\n",
       " 14218,\n",
       " 4841,\n",
       " 4714,\n",
       " 3649,\n",
       " 4831,\n",
       " 8453,\n",
       " 7959,\n",
       " 2775,\n",
       " 9223,\n",
       " 1731,\n",
       " 17228,\n",
       " 3001,\n",
       " 9226,\n",
       " 9233,\n",
       " 7799,\n",
       " 4834,\n",
       " 4795,\n",
       " 3055,\n",
       " 4660,\n",
       " 4750,\n",
       " 7942,\n",
       " 8015,\n",
       " 7882,\n",
       " 3037,\n",
       " 3058,\n",
       " 3856,\n",
       " 7989,\n",
       " 4674,\n",
       " 4796,\n",
       " 5508,\n",
       " 9217,\n",
       " 3141,\n",
       " 7237,\n",
       " 4097,\n",
       " 13091,\n",
       " 5732,\n",
       " 14207,\n",
       " 7266,\n",
       " 3844,\n",
       " 7255,\n",
       " 2918,\n",
       " 9224,\n",
       " 9210,\n",
       " 7958,\n",
       " 7254,\n",
       " 10706,\n",
       " 7700,\n",
       " 4697,\n",
       " 3906,\n",
       " 7928,\n",
       " 6651,\n",
       " 8464,\n",
       " 7960,\n",
       " 9214,\n",
       " 4119,\n",
       " 2484,\n",
       " 10707,\n",
       " 14396,\n",
       " 14219,\n",
       " 4094,\n",
       " 8468,\n",
       " 8512,\n",
       " 9598,\n",
       " 7097,\n",
       " 7263,\n",
       " 9248,\n",
       " 3847,\n",
       " 14214,\n",
       " 14215,\n",
       " 4113,\n",
       " 14648,\n",
       " 4148,\n",
       " 9294,\n",
       " 7892,\n",
       " 7878,\n",
       " 3846,\n",
       " 7231,\n",
       " 2647,\n",
       " 14185,\n",
       " 5502,\n",
       " 4691,\n",
       " 9295,\n",
       " 9298,\n",
       " 802,\n",
       " 5573,\n",
       " 5484,\n",
       " 7969,\n",
       " 7987,\n",
       " 9103,\n",
       " 14160,\n",
       " 7230,\n",
       " 9189,\n",
       " 3848,\n",
       " 4779,\n",
       " 4676,\n",
       " 9219,\n",
       " 9247,\n",
       " 4675,\n",
       " 8005,\n",
       " 8125,\n",
       " 8031,\n",
       " 8039,\n",
       " 8045,\n",
       " 4065,\n",
       " 2684,\n",
       " 8061,\n",
       " 8121,\n",
       " 8113,\n",
       " 4702,\n",
       " 8089,\n",
       " 8091,\n",
       " 8071,\n",
       " 7262,\n",
       " 3859,\n",
       " 4846,\n",
       " 14415,\n",
       " 9570,\n",
       " 7941,\n",
       " 3909,\n",
       " 7781,\n",
       " 8123,\n",
       " 8516,\n",
       " 20132,\n",
       " 2843,\n",
       " 20092,\n",
       " 4770,\n",
       " 20093,\n",
       " 20094,\n",
       " 7569,\n",
       " 7121,\n",
       " 4246,\n",
       " 4247,\n",
       " 3957,\n",
       " 6781,\n",
       " 7115,\n",
       " 4572,\n",
       " 5492,\n",
       " 8278,\n",
       " 4150,\n",
       " 8442,\n",
       " 9579,\n",
       " 4745,\n",
       " 8281,\n",
       " 8279,\n",
       " 5493,\n",
       " 7264,\n",
       " 7947,\n",
       " 5514,\n",
       " 9212,\n",
       " 5545,\n",
       " 4062,\n",
       " 8548,\n",
       " 3896,\n",
       " 7243,\n",
       " 9196,\n",
       " 4268,\n",
       " 8065,\n",
       " 6652,\n",
       " 7935,\n",
       " 9206,\n",
       " 17162,\n",
       " 8026,\n",
       " 7103,\n",
       " 20218,\n",
       " 4085,\n",
       " 4069,\n",
       " 7265,\n",
       " 8231,\n",
       " 4464,\n",
       " 7961,\n",
       " 9571,\n",
       " 3922,\n",
       " 7688,\n",
       " 4078,\n",
       " 7871,\n",
       " 9273,\n",
       " 589,\n",
       " 4798,\n",
       " 3936,\n",
       " 7238,\n",
       " 7275,\n",
       " 9259,\n",
       " 5565,\n",
       " 7931,\n",
       " 3866,\n",
       " 9260,\n",
       " 7248,\n",
       " 7274,\n",
       " 17166,\n",
       " 4748,\n",
       " 4808,\n",
       " 4706,\n",
       " 4081,\n",
       " 7999,\n",
       " 17170,\n",
       " 7271,\n",
       " 7951,\n",
       " 5544,\n",
       " 4840,\n",
       " 7118,\n",
       " 4153,\n",
       " 2650,\n",
       " 4733,\n",
       " 4731,\n",
       " 4732,\n",
       " 4816,\n",
       " 2642,\n",
       " 8079,\n",
       " 4105,\n",
       " 4838,\n",
       " 5504,\n",
       " 9246,\n",
       " 3903,\n",
       " 7953,\n",
       " 5574,\n",
       " 7884,\n",
       " 9203,\n",
       " 5472,\n",
       " 9102,\n",
       " 3881,\n",
       " 7269,\n",
       " 9250,\n",
       " 4072,\n",
       " 5567,\n",
       " 8115,\n",
       " 9225,\n",
       " 4109,\n",
       " 7933,\n",
       " 5548,\n",
       " 4806,\n",
       " 4064,\n",
       " 6779,\n",
       " 20113,\n",
       " 4802,\n",
       " 2719,\n",
       " 14222,\n",
       " 8000,\n",
       " 7246,\n",
       " 8552,\n",
       " 5554,\n",
       " 3946,\n",
       " 7932,\n",
       " 2844,\n",
       " 3950,\n",
       " 3956,\n",
       " 3959,\n",
       " 7968,\n",
       " 5546,\n",
       " 5558,\n",
       " 9261,\n",
       " 5495,\n",
       " 4810,\n",
       " 8059,\n",
       " 4106,\n",
       " 5351,\n",
       " 3900,\n",
       " 3945,\n",
       " 4329,\n",
       " 8443,\n",
       " 8053,\n",
       " 5510,\n",
       " 5475,\n",
       " 9201,\n",
       " 5555,\n",
       " 7112,\n",
       " 8093,\n",
       " 3865,\n",
       " 2753,\n",
       " 5487,\n",
       " 9062,\n",
       " 9198,\n",
       " 3855,\n",
       " 4771,\n",
       " 5498,\n",
       " 9220,\n",
       " 8471,\n",
       " 7125,\n",
       " 4158,\n",
       " 4111,\n",
       " 4465,\n",
       " 9218,\n",
       " 4285,\n",
       " 7956,\n",
       " 2854,\n",
       " 2668,\n",
       " 9207,\n",
       " 4809,\n",
       " 7955,\n",
       " 7270,\n",
       " 2727,\n",
       " 8230,\n",
       " 9262,\n",
       " 5471,\n",
       " 4079,\n",
       " 4659,\n",
       " 4726,\n",
       " 14192,\n",
       " 668,\n",
       " 4700,\n",
       " 9183,\n",
       " 8524,\n",
       " 5479,\n",
       " 8234,\n",
       " 5483,\n",
       " 4783,\n",
       " 5480,\n",
       " 8469,\n",
       " 8791,\n",
       " 4703,\n",
       " 8055,\n",
       " 9184,\n",
       " 7967,\n",
       " 10415,\n",
       " 8452,\n",
       " 4054,\n",
       " 4328,\n",
       " 7985,\n",
       " 7976,\n",
       " 4587,\n",
       " 7772,\n",
       " 7873,\n",
       " 13162,\n",
       " 4679,\n",
       " 4690,\n",
       " 7250,\n",
       " 9197,\n",
       " 8439,\n",
       " 4723,\n",
       " 4677,\n",
       " 4107,\n",
       " 4815,\n",
       " 3892,\n",
       " 5506,\n",
       " 5507,\n",
       " 4098,\n",
       " 4685,\n",
       " 14208,\n",
       " 3921,\n",
       " 13194,\n",
       " 9099,\n",
       " 3876,\n",
       " 9216,\n",
       " 8446,\n",
       " 7974,\n",
       " 9244,\n",
       " 7929,\n",
       " 4655,\n",
       " 4784,\n",
       " 2825,\n",
       " 4787,\n",
       " 14255,\n",
       " 5485,\n",
       " 2869,\n",
       " 3883,\n",
       " 5559,\n",
       " 4752,\n",
       " 14203,\n",
       " 9573,\n",
       " 2503,\n",
       " 7247,\n",
       " 3313,\n",
       " 4084,\n",
       " 14254,\n",
       " 4823,\n",
       " 10607,\n",
       " 8017,\n",
       " 14181,\n",
       " 4671,\n",
       " 8546,\n",
       " 8013,\n",
       " 2848,\n",
       " 5568,\n",
       " 4686,\n",
       " 7883,\n",
       " 9580,\n",
       " 8465,\n",
       " 8551,\n",
       " 14213,\n",
       " 8463,\n",
       " 9191,\n",
       " 5547,\n",
       " 8246,\n",
       " 4747,\n",
       " 8544,\n",
       " 8051,\n",
       " 4300,\n",
       " 2695,\n",
       " 4089,\n",
       " 13292,\n",
       " 6691,\n",
       " 6690,\n",
       " 9245,\n",
       " 7278,\n",
       " 9143,\n",
       " 8127,\n",
       " 8033,\n",
       " 9173,\n",
       " 11639,\n",
       " 9566,\n",
       " 8069,\n",
       " 8458,\n",
       " 8024,\n",
       " 4695,\n",
       " 9215,\n",
       " 9055,\n",
       " 4092,\n",
       " 9750,\n",
       " 7277,\n",
       " 3873,\n",
       " 4270,\n",
       " 4102,\n",
       " 4475,\n",
       " 8285,\n",
       " 4694,\n",
       " 7239,\n",
       " 7779,\n",
       " 7783,\n",
       " 7778,\n",
       " 4282,\n",
       " 14229,\n",
       " 7776,\n",
       " 4159,\n",
       " 8233,\n",
       " 9186,\n",
       " 650,\n",
       " 2520,\n",
       " 8467,\n",
       " 5550,\n",
       " 8232,\n",
       " 8520,\n",
       " 9293,\n",
       " 8555,\n",
       " 7120,\n",
       " 4157,\n",
       " 7936,\n",
       " 16882,\n",
       " 9239,\n",
       " 9235,\n",
       " 3974,\n",
       " 3145,\n",
       " 4698,\n",
       " 7870,\n",
       " 14154,\n",
       " 4682,\n",
       " 4707,\n",
       " 9169,\n",
       " 9274,\n",
       " 9241,\n",
       " 4055,\n",
       " 8554,\n",
       " 9071,\n",
       " 6674,\n",
       " 4474,\n",
       " 3867,\n",
       " 4061,\n",
       " 1218,\n",
       " 9243,\n",
       " 9575,\n",
       " 5473,\n",
       " 8277,\n",
       " 4057,\n",
       " 7983,\n",
       " 2864,\n",
       " 5511,\n",
       " 14151,\n",
       " 9267,\n",
       " 8553,\n",
       " 9128,\n",
       " 11637,\n",
       " 9748,\n",
       " 7971,\n",
       " 7973,\n",
       " 9063,\n",
       " 9089,\n",
       " 9060,\n",
       " 3123,\n",
       " 4473,\n",
       " 3908,\n",
       " 9277,\n",
       " 20116,\n",
       " 7797,\n",
       " 4565,\n",
       " 9593,\n",
       " 9596,\n",
       " 9181,\n",
       " 4801,\n",
       " 7794,\n",
       " 3888,\n",
       " 9257,\n",
       " 2517,\n",
       " 9061,\n",
       " 8457,\n",
       " 17074,\n",
       " 8169,\n",
       " 14209,\n",
       " 9153,\n",
       " 9249,\n",
       " 5564,\n",
       " 8511,\n",
       " 14183,\n",
       " 7996,\n",
       " 9058,\n",
       " 2518,\n",
       " 14223,\n",
       " 8513,\n",
       " 9088,\n",
       " 8119,\n",
       " 9291,\n",
       " 4066,\n",
       " 8129,\n",
       " 9190,\n",
       " 8001,\n",
       " 4720,\n",
       " 5349,\n",
       " 7109,\n",
       " 5347,\n",
       " 9284,\n",
       " 815,\n",
       " 4805,\n",
       " 20161,\n",
       " 4151,\n",
       " 8057,\n",
       " 9251,\n",
       " 7258,\n",
       " 8547,\n",
       " 8445,\n",
       " 4754,\n",
       " 9258,\n",
       " 3929,\n",
       " 9159,\n",
       " 17073,\n",
       " 3912,\n",
       " 4813,\n",
       " 14157,\n",
       " 7992,\n",
       " 7946,\n",
       " 11638,\n",
       " 12329,\n",
       " 7930,\n",
       " 4688,\n",
       " 16699,\n",
       " 2747,\n",
       " 9054,\n",
       " 10606,\n",
       " 14179,\n",
       " 9255,\n",
       " 3850,\n",
       " 9211,\n",
       " 9162,\n",
       " 8990,\n",
       " 4476,\n",
       " 4708,\n",
       " 3107,\n",
       " 7259,\n",
       " 4807,\n",
       " 16683,\n",
       " 3875,\n",
       " 7997,\n",
       " 3939,\n",
       " 4699,\n",
       " 2473,\n",
       " 14256,\n",
       " 9264,\n",
       " 9187,\n",
       " 4793,\n",
       " 4689,\n",
       " 9289,\n",
       " 14201,\n",
       " 3905,\n",
       " 17076,\n",
       " 14187,\n",
       " 7774,\n",
       " 9297,\n",
       " 7787,\n",
       " 2746,\n",
       " 9074,\n",
       " 3915,\n",
       " 2856,\n",
       " 14398,\n",
       " 14241,\n",
       " 3861,\n",
       " 9194,\n",
       " 7126,\n",
       " 4693,\n",
       " 14163,\n",
       " 4577,\n",
       " 662,\n",
       " 14152,\n",
       " 11705,\n",
       " 9256,\n",
       " 5476,\n",
       " 5501,\n",
       " 9280,\n",
       " 14226,\n",
       " 14202,\n",
       " 7791,\n",
       " 3934,\n",
       " 14172,\n",
       " 3933,\n",
       " 14411,\n",
       " 14412,\n",
       " 9057,\n",
       " 3871,\n",
       " 4469,\n",
       " 4567,\n",
       " 4467,\n",
       " 9227,\n",
       " 4327,\n",
       " 8459,\n",
       " 9242,\n",
       " 9238,\n",
       " 9254,\n",
       " 4568,\n",
       " 8095,\n",
       " 8519,\n",
       " 12328,\n",
       " 9076,\n",
       " 12327,\n",
       " 4776,\n",
       " 14232,\n",
       " 4149,\n",
       " 9168,\n",
       " 14155,\n",
       " 10608,\n",
       " 4680,\n",
       " 14177,\n",
       " 7890,\n",
       " 2649,\n",
       " 4575,\n",
       " 9193,\n",
       " 9149,\n",
       " 14230,\n",
       " 3852,\n",
       " 2691,\n",
       " 7245,\n",
       " 14233,\n",
       " 9292,\n",
       " 13453,\n",
       " 3955,\n",
       " 14224,\n",
       " 13459,\n",
       " 14168,\n",
       " 12333,\n",
       " 5562,\n",
       " 7240,\n",
       " 2694,\n",
       " 2692,\n",
       " 2693,\n",
       " 2516,\n",
       " 9067,\n",
       " 9083,\n",
       " ...]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 730,
   "id": "lonely-brown",
   "metadata": {},
   "outputs": [],
   "source": [
    "def symbolmetric(m,pingguzhibiao):\n",
    "    num = 0\n",
    "    lenlen = len(m)\n",
    "    if lenlen ==1:\n",
    "        return 0\n",
    "    for i in range(len(m)):\n",
    "        for j in range(len(m)):\n",
    "            if m[i][j]>=pingguzhibiao and i!=j:\n",
    "                num+=1\n",
    "    return(num/(lenlen*(lenlen))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 729,
   "id": "critical-aruba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3703\n",
      "3702\n",
      "3704\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.290754</td>\n",
       "      <td>0.211993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.290754</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.399406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.211993</td>\n",
       "      <td>0.399406</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2\n",
       "0  1.000000  0.290754  0.211993\n",
       "1  0.290754  1.000000  0.399406\n",
       "2  0.211993  0.399406  1.000000"
      ]
     },
     "execution_count": 729,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filename = 25\n",
    "vectorlist = []\n",
    "\n",
    "if recdic[filename] in q:\n",
    "    for symbol in q[recdic[filename]]:\n",
    "        if symbol in key:\n",
    "            print(symbol)\n",
    "            vectorlist.append(qqq[symbol])\n",
    "    if len(vectorlist) !=0:\n",
    "        m = cosine_similarity(vectorlist)\n",
    "        mm = np.maximum(m, -m)\n",
    "c=pd.DataFrame(mm)\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 738,
   "id": "assisted-chair",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alias.c\n",
      "alias.h\n",
      "builtins/mkbuiltins.c\n",
      "command.h\n",
      "externs.h\n",
      "general.h\n",
      "hashlib.c\n",
      "hashlib.h\n",
      "lib/readline/complete.c\n",
      "lib/readline/funmap.c\n",
      "lib/readline/tilde.c\n",
      "lib/readline/vi_mode.c\n",
      "lib/readline/xmalloc.h\n",
      "lib/sh/stringvec.c\n",
      "lib/tilde/tilde.c\n",
      "pcomplete.c\n",
      "pcomplete.h\n",
      "xmalloc.c\n",
      "xmalloc.h\n",
      "array.c\n",
      "arrayfunc.h\n",
      "array.h\n",
      "assoc.h\n",
      "builtins/common.h\n",
      "dispose_cmd.h\n",
      "error.h\n",
      "lib/glob/smatch.c\n",
      "lib/glob/xmbsrtowcs.c\n",
      "lib/readline/rlshell.h\n",
      "lib/readline/shell.c\n",
      "lib/sh/casemod.c\n",
      "lib/sh/itos.c\n",
      "lib/sh/shquote.c\n",
      "make_cmd.c\n",
      "make_cmd.h\n",
      "shell.h\n",
      "sig.h\n",
      "subst.c\n",
      "subst.h\n",
      "unwind_prot.h\n",
      "variables.h\n",
      "arrayfunc.c\n",
      "assoc.c\n",
      "bashline.c\n",
      "builtins/common.c\n",
      "builtins/evalfile.c\n",
      "builtins/evalstring.c\n",
      "dispose_cmd.c\n",
      "error.c\n",
      "eval.c\n",
      "execute_cmd.c\n",
      "general.c\n",
      "include/shmbutil.h\n",
      "jobs.c\n",
      "pathexp.c\n",
      "pathexp.h\n",
      "redir.c\n",
      "shell.c\n",
      "sig.c\n",
      "stringlib.c\n",
      "trap.c\n",
      "variables.c\n",
      "y.tab.c\n",
      "bashhist.c\n",
      "bashhist.h\n",
      "bashline.h\n",
      "flags.c\n",
      "flags.h\n",
      "input.h\n",
      "lib/glob/glob.c\n",
      "lib/glob/glob.h\n",
      "lib/glob/strmatch.c\n",
      "lib/glob/strmatch.h\n",
      "lib/readline/histexpand.c\n",
      "lib/readline/histfile.c\n",
      "lib/readline/history.c\n",
      "lib/readline/history.h\n",
      "lib/readline/readline.c\n",
      "lib/readline/readline.h\n",
      "lib/sh/unicode.c\n",
      "execute_cmd.h\n",
      "findcmd.c\n",
      "findcmd.h\n",
      "lib/readline/bind.c\n",
      "lib/readline/compat.c\n",
      "lib/readline/display.c\n",
      "lib/readline/input.c\n",
      "lib/readline/keymaps.h\n",
      "lib/readline/kill.c\n",
      "lib/readline/macro.c\n",
      "lib/readline/misc.c\n",
      "lib/readline/rltty.c\n",
      "lib/readline/tcap.h\n",
      "lib/readline/terminal.c\n",
      "lib/readline/text.c\n",
      "lib/readline/tilde.h\n",
      "lib/readline/undo.c\n",
      "lib/readline/util.c\n",
      "lib/sh/makepath.c\n",
      "lib/sh/pathphys.c\n",
      "lib/termcap/termcap.c\n",
      "pcomplib.c\n",
      "support/bashversion.c\n",
      "version.c\n",
      "braces.c\n",
      "builtins/bashgetopt.c\n",
      "builtins/bashgetopt.h\n",
      "unwind_prot.c\n",
      "builtins/builtext.h\n",
      "lib/tilde/tilde.h\n",
      "copy_cmd.c\n",
      "input.c\n",
      "jobs.h\n",
      "trap.h\n",
      "lib/sh/stringlist.c\n",
      "print_cmd.c\n",
      "lib/sh/strtrans.c\n",
      "lib/sh/zmapfd.c\n",
      "lib/malloc/malloc.c\n",
      "lib/sh/zcatfd.c\n",
      "redir.h\n",
      "lib/sh/tmpfile.c\n",
      "builtins/getopt.c\n",
      "builtins/getopt.h\n",
      "hashcmd.c\n",
      "hashcmd.h\n",
      "lib/sh/zgetline.c\n",
      "lib/sh/zread.c\n",
      "lib/readline/rlmbutil.h\n",
      "mailcheck.c\n",
      "lib/readline/signals.c\n",
      "test.c\n",
      "test.h\n",
      "lib/sh/timeval.c\n",
      "lib/sh/oslib.c\n",
      "list.c\n",
      "lib/sh/eaccess.c\n",
      "lib/sh/shmbchar.c\n",
      "lib/sh/winsize.c\n",
      "lib/glob/gmisc.c\n",
      "lib/sh/getenv.c\n",
      "lib/malloc/shmalloc.h\n",
      "lib/readline/xmalloc.c\n",
      "lib/readline/isearch.c\n",
      "lib/readline/mbutil.c\n",
      "lib/readline/rlprivate.h\n",
      "lib/readline/search.c\n",
      "locale.c\n",
      "mailcheck.h\n",
      "support/mksignames.c\n"
     ]
    }
   ],
   "source": [
    "average = 0\n",
    "fenmu =0\n",
    "for filename in recdic:\n",
    "    vectorlist = []\n",
    "    if recdic[filename] in q:\n",
    "        for symbol in q[recdic[filename]]:\n",
    "            if symbol in key:\n",
    "                vectorlist.append(qqq[symbol])\n",
    "        if len(vectorlist) !=0 and len(vectorlist) !=1:\n",
    "            m = cosine_similarity(vectorlist)\n",
    "            mm = np.maximum(m, -m)\n",
    "            bubu=symbolmetric(mm,0.16)\n",
    "            print(recdic[filename])\n",
    "            average+=bubu\n",
    "            fenmu+=1\n",
    "            \n",
    "#             print(recdic[filename])\n",
    "#             print(filename)\n",
    "#             print()\n",
    "#         else:\n",
    "#             print(\"符号没有vecotr的文件名称\"+\" \"+recdic[filename])\n",
    "            \n",
    "#     else:\n",
    "#         print(\"没有提取到的文件名称\"+\" \"+recdic[filename])\n",
    "#     else:\n",
    "#         m=[0]\n",
    "#     pd.DataFrame(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 736,
   "id": "confused-natural",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6149311951160479"
      ]
     },
     "execution_count": 736,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "average/fenmu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "heavy-hunter",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 655,
   "id": "corrected-atlanta",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = cosine_similarity(value)\n",
    "c=pd.DataFrame(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 656,
   "id": "north-allergy",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 656,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 658,
   "id": "liberal-fountain",
   "metadata": {},
   "outputs": [],
   "source": [
    "mm = np.maximum(m, -m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 660,
   "id": "secret-sixth",
   "metadata": {},
   "outputs": [],
   "source": [
    "c=pd.DataFrame(mm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 661,
   "id": "essential-watts",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>1143</th>\n",
       "      <th>1144</th>\n",
       "      <th>1145</th>\n",
       "      <th>1146</th>\n",
       "      <th>1147</th>\n",
       "      <th>1148</th>\n",
       "      <th>1149</th>\n",
       "      <th>1150</th>\n",
       "      <th>1151</th>\n",
       "      <th>1152</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.077693</td>\n",
       "      <td>0.294807</td>\n",
       "      <td>0.091430</td>\n",
       "      <td>0.337997</td>\n",
       "      <td>0.478794</td>\n",
       "      <td>0.439387</td>\n",
       "      <td>0.491918</td>\n",
       "      <td>0.555327</td>\n",
       "      <td>0.174763</td>\n",
       "      <td>...</td>\n",
       "      <td>0.405459</td>\n",
       "      <td>0.264322</td>\n",
       "      <td>0.218779</td>\n",
       "      <td>0.383507</td>\n",
       "      <td>0.529830</td>\n",
       "      <td>0.391600</td>\n",
       "      <td>0.463067</td>\n",
       "      <td>0.270247</td>\n",
       "      <td>0.089798</td>\n",
       "      <td>0.711004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.077693</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.126786</td>\n",
       "      <td>0.109063</td>\n",
       "      <td>0.180276</td>\n",
       "      <td>0.027738</td>\n",
       "      <td>0.191538</td>\n",
       "      <td>0.096924</td>\n",
       "      <td>0.089351</td>\n",
       "      <td>0.113924</td>\n",
       "      <td>...</td>\n",
       "      <td>0.318447</td>\n",
       "      <td>0.258964</td>\n",
       "      <td>0.186660</td>\n",
       "      <td>0.389741</td>\n",
       "      <td>0.189241</td>\n",
       "      <td>0.161614</td>\n",
       "      <td>0.048394</td>\n",
       "      <td>0.252377</td>\n",
       "      <td>0.275051</td>\n",
       "      <td>0.113410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.294807</td>\n",
       "      <td>0.126786</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.259657</td>\n",
       "      <td>0.571874</td>\n",
       "      <td>0.317886</td>\n",
       "      <td>0.285163</td>\n",
       "      <td>0.128361</td>\n",
       "      <td>0.156125</td>\n",
       "      <td>0.221364</td>\n",
       "      <td>...</td>\n",
       "      <td>0.488042</td>\n",
       "      <td>0.359850</td>\n",
       "      <td>0.263919</td>\n",
       "      <td>0.434989</td>\n",
       "      <td>0.440703</td>\n",
       "      <td>0.030336</td>\n",
       "      <td>0.320276</td>\n",
       "      <td>0.130965</td>\n",
       "      <td>0.137983</td>\n",
       "      <td>0.435818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.091430</td>\n",
       "      <td>0.109063</td>\n",
       "      <td>0.259657</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.240268</td>\n",
       "      <td>0.137877</td>\n",
       "      <td>0.095638</td>\n",
       "      <td>0.063211</td>\n",
       "      <td>0.036920</td>\n",
       "      <td>0.822750</td>\n",
       "      <td>...</td>\n",
       "      <td>0.100144</td>\n",
       "      <td>0.012187</td>\n",
       "      <td>0.106914</td>\n",
       "      <td>0.036487</td>\n",
       "      <td>0.008100</td>\n",
       "      <td>0.014560</td>\n",
       "      <td>0.132649</td>\n",
       "      <td>0.087322</td>\n",
       "      <td>0.325120</td>\n",
       "      <td>0.004803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.337997</td>\n",
       "      <td>0.180276</td>\n",
       "      <td>0.571874</td>\n",
       "      <td>0.240268</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.334796</td>\n",
       "      <td>0.281813</td>\n",
       "      <td>0.119186</td>\n",
       "      <td>0.194218</td>\n",
       "      <td>0.295784</td>\n",
       "      <td>...</td>\n",
       "      <td>0.499048</td>\n",
       "      <td>0.275480</td>\n",
       "      <td>0.239733</td>\n",
       "      <td>0.448760</td>\n",
       "      <td>0.482371</td>\n",
       "      <td>0.192436</td>\n",
       "      <td>0.323820</td>\n",
       "      <td>0.188967</td>\n",
       "      <td>0.067681</td>\n",
       "      <td>0.326002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1148</th>\n",
       "      <td>0.391600</td>\n",
       "      <td>0.161614</td>\n",
       "      <td>0.030336</td>\n",
       "      <td>0.014560</td>\n",
       "      <td>0.192436</td>\n",
       "      <td>0.024372</td>\n",
       "      <td>0.117045</td>\n",
       "      <td>0.262193</td>\n",
       "      <td>0.204994</td>\n",
       "      <td>0.089971</td>\n",
       "      <td>...</td>\n",
       "      <td>0.342659</td>\n",
       "      <td>0.067033</td>\n",
       "      <td>0.147970</td>\n",
       "      <td>0.222644</td>\n",
       "      <td>0.300761</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.193975</td>\n",
       "      <td>0.477112</td>\n",
       "      <td>0.141367</td>\n",
       "      <td>0.377308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1149</th>\n",
       "      <td>0.463067</td>\n",
       "      <td>0.048394</td>\n",
       "      <td>0.320276</td>\n",
       "      <td>0.132649</td>\n",
       "      <td>0.323820</td>\n",
       "      <td>0.430543</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.330710</td>\n",
       "      <td>0.219213</td>\n",
       "      <td>0.047726</td>\n",
       "      <td>...</td>\n",
       "      <td>0.380707</td>\n",
       "      <td>0.226100</td>\n",
       "      <td>0.398770</td>\n",
       "      <td>0.289582</td>\n",
       "      <td>0.410427</td>\n",
       "      <td>0.193975</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.381073</td>\n",
       "      <td>0.152622</td>\n",
       "      <td>0.485475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1150</th>\n",
       "      <td>0.270247</td>\n",
       "      <td>0.252377</td>\n",
       "      <td>0.130965</td>\n",
       "      <td>0.087322</td>\n",
       "      <td>0.188967</td>\n",
       "      <td>0.125836</td>\n",
       "      <td>0.184207</td>\n",
       "      <td>0.310081</td>\n",
       "      <td>0.258113</td>\n",
       "      <td>0.018925</td>\n",
       "      <td>...</td>\n",
       "      <td>0.397713</td>\n",
       "      <td>0.236826</td>\n",
       "      <td>0.190058</td>\n",
       "      <td>0.348684</td>\n",
       "      <td>0.254701</td>\n",
       "      <td>0.477112</td>\n",
       "      <td>0.381073</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.199637</td>\n",
       "      <td>0.440301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1151</th>\n",
       "      <td>0.089798</td>\n",
       "      <td>0.275051</td>\n",
       "      <td>0.137983</td>\n",
       "      <td>0.325120</td>\n",
       "      <td>0.067681</td>\n",
       "      <td>0.125626</td>\n",
       "      <td>0.269321</td>\n",
       "      <td>0.153803</td>\n",
       "      <td>0.166500</td>\n",
       "      <td>0.394585</td>\n",
       "      <td>...</td>\n",
       "      <td>0.202675</td>\n",
       "      <td>0.321884</td>\n",
       "      <td>0.296698</td>\n",
       "      <td>0.409516</td>\n",
       "      <td>0.200808</td>\n",
       "      <td>0.141367</td>\n",
       "      <td>0.152622</td>\n",
       "      <td>0.199637</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.261412</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1152</th>\n",
       "      <td>0.711004</td>\n",
       "      <td>0.113410</td>\n",
       "      <td>0.435818</td>\n",
       "      <td>0.004803</td>\n",
       "      <td>0.326002</td>\n",
       "      <td>0.471091</td>\n",
       "      <td>0.351979</td>\n",
       "      <td>0.483336</td>\n",
       "      <td>0.547555</td>\n",
       "      <td>0.028440</td>\n",
       "      <td>...</td>\n",
       "      <td>0.672761</td>\n",
       "      <td>0.529515</td>\n",
       "      <td>0.256736</td>\n",
       "      <td>0.747498</td>\n",
       "      <td>0.576465</td>\n",
       "      <td>0.377308</td>\n",
       "      <td>0.485475</td>\n",
       "      <td>0.440301</td>\n",
       "      <td>0.261412</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1153 rows × 1153 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6     \\\n",
       "0     1.000000  0.077693  0.294807  0.091430  0.337997  0.478794  0.439387   \n",
       "1     0.077693  1.000000  0.126786  0.109063  0.180276  0.027738  0.191538   \n",
       "2     0.294807  0.126786  1.000000  0.259657  0.571874  0.317886  0.285163   \n",
       "3     0.091430  0.109063  0.259657  1.000000  0.240268  0.137877  0.095638   \n",
       "4     0.337997  0.180276  0.571874  0.240268  1.000000  0.334796  0.281813   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "1148  0.391600  0.161614  0.030336  0.014560  0.192436  0.024372  0.117045   \n",
       "1149  0.463067  0.048394  0.320276  0.132649  0.323820  0.430543  0.189671   \n",
       "1150  0.270247  0.252377  0.130965  0.087322  0.188967  0.125836  0.184207   \n",
       "1151  0.089798  0.275051  0.137983  0.325120  0.067681  0.125626  0.269321   \n",
       "1152  0.711004  0.113410  0.435818  0.004803  0.326002  0.471091  0.351979   \n",
       "\n",
       "          7         8         9     ...      1143      1144      1145  \\\n",
       "0     0.491918  0.555327  0.174763  ...  0.405459  0.264322  0.218779   \n",
       "1     0.096924  0.089351  0.113924  ...  0.318447  0.258964  0.186660   \n",
       "2     0.128361  0.156125  0.221364  ...  0.488042  0.359850  0.263919   \n",
       "3     0.063211  0.036920  0.822750  ...  0.100144  0.012187  0.106914   \n",
       "4     0.119186  0.194218  0.295784  ...  0.499048  0.275480  0.239733   \n",
       "...        ...       ...       ...  ...       ...       ...       ...   \n",
       "1148  0.262193  0.204994  0.089971  ...  0.342659  0.067033  0.147970   \n",
       "1149  0.330710  0.219213  0.047726  ...  0.380707  0.226100  0.398770   \n",
       "1150  0.310081  0.258113  0.018925  ...  0.397713  0.236826  0.190058   \n",
       "1151  0.153803  0.166500  0.394585  ...  0.202675  0.321884  0.296698   \n",
       "1152  0.483336  0.547555  0.028440  ...  0.672761  0.529515  0.256736   \n",
       "\n",
       "          1146      1147      1148      1149      1150      1151      1152  \n",
       "0     0.383507  0.529830  0.391600  0.463067  0.270247  0.089798  0.711004  \n",
       "1     0.389741  0.189241  0.161614  0.048394  0.252377  0.275051  0.113410  \n",
       "2     0.434989  0.440703  0.030336  0.320276  0.130965  0.137983  0.435818  \n",
       "3     0.036487  0.008100  0.014560  0.132649  0.087322  0.325120  0.004803  \n",
       "4     0.448760  0.482371  0.192436  0.323820  0.188967  0.067681  0.326002  \n",
       "...        ...       ...       ...       ...       ...       ...       ...  \n",
       "1148  0.222644  0.300761  1.000000  0.193975  0.477112  0.141367  0.377308  \n",
       "1149  0.289582  0.410427  0.193975  1.000000  0.381073  0.152622  0.485475  \n",
       "1150  0.348684  0.254701  0.477112  0.381073  1.000000  0.199637  0.440301  \n",
       "1151  0.409516  0.200808  0.141367  0.152622  0.199637  1.000000  0.261412  \n",
       "1152  0.747498  0.576465  0.377308  0.485475  0.440301  0.261412  1.000000  \n",
       "\n",
       "[1153 rows x 1153 columns]"
      ]
     },
     "execution_count": 661,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 663,
   "id": "overhead-trustee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>1143</th>\n",
       "      <th>1144</th>\n",
       "      <th>1145</th>\n",
       "      <th>1146</th>\n",
       "      <th>1147</th>\n",
       "      <th>1148</th>\n",
       "      <th>1149</th>\n",
       "      <th>1150</th>\n",
       "      <th>1151</th>\n",
       "      <th>1152</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.077693</td>\n",
       "      <td>0.294807</td>\n",
       "      <td>-0.091430</td>\n",
       "      <td>0.337997</td>\n",
       "      <td>0.478794</td>\n",
       "      <td>0.439387</td>\n",
       "      <td>0.491918</td>\n",
       "      <td>0.555327</td>\n",
       "      <td>-0.174763</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.405459</td>\n",
       "      <td>-0.264322</td>\n",
       "      <td>-0.218779</td>\n",
       "      <td>-0.383507</td>\n",
       "      <td>-0.529830</td>\n",
       "      <td>-0.391600</td>\n",
       "      <td>-0.463067</td>\n",
       "      <td>-0.270247</td>\n",
       "      <td>-0.089798</td>\n",
       "      <td>-0.711004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.077693</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.126786</td>\n",
       "      <td>0.109063</td>\n",
       "      <td>0.180276</td>\n",
       "      <td>-0.027738</td>\n",
       "      <td>0.191538</td>\n",
       "      <td>-0.096924</td>\n",
       "      <td>0.089351</td>\n",
       "      <td>0.113924</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.318447</td>\n",
       "      <td>-0.258964</td>\n",
       "      <td>-0.186660</td>\n",
       "      <td>-0.389741</td>\n",
       "      <td>-0.189241</td>\n",
       "      <td>-0.161614</td>\n",
       "      <td>-0.048394</td>\n",
       "      <td>-0.252377</td>\n",
       "      <td>-0.275051</td>\n",
       "      <td>-0.113410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.294807</td>\n",
       "      <td>0.126786</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.259657</td>\n",
       "      <td>0.571874</td>\n",
       "      <td>0.317886</td>\n",
       "      <td>0.285163</td>\n",
       "      <td>0.128361</td>\n",
       "      <td>0.156125</td>\n",
       "      <td>-0.221364</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.488042</td>\n",
       "      <td>-0.359850</td>\n",
       "      <td>-0.263919</td>\n",
       "      <td>-0.434989</td>\n",
       "      <td>-0.440703</td>\n",
       "      <td>0.030336</td>\n",
       "      <td>-0.320276</td>\n",
       "      <td>-0.130965</td>\n",
       "      <td>-0.137983</td>\n",
       "      <td>-0.435818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.091430</td>\n",
       "      <td>0.109063</td>\n",
       "      <td>-0.259657</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.240268</td>\n",
       "      <td>-0.137877</td>\n",
       "      <td>0.095638</td>\n",
       "      <td>0.063211</td>\n",
       "      <td>0.036920</td>\n",
       "      <td>0.822750</td>\n",
       "      <td>...</td>\n",
       "      <td>0.100144</td>\n",
       "      <td>0.012187</td>\n",
       "      <td>-0.106914</td>\n",
       "      <td>-0.036487</td>\n",
       "      <td>-0.008100</td>\n",
       "      <td>-0.014560</td>\n",
       "      <td>0.132649</td>\n",
       "      <td>0.087322</td>\n",
       "      <td>-0.325120</td>\n",
       "      <td>-0.004803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.337997</td>\n",
       "      <td>0.180276</td>\n",
       "      <td>0.571874</td>\n",
       "      <td>-0.240268</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.334796</td>\n",
       "      <td>0.281813</td>\n",
       "      <td>0.119186</td>\n",
       "      <td>0.194218</td>\n",
       "      <td>-0.295784</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.499048</td>\n",
       "      <td>-0.275480</td>\n",
       "      <td>-0.239733</td>\n",
       "      <td>-0.448760</td>\n",
       "      <td>-0.482371</td>\n",
       "      <td>-0.192436</td>\n",
       "      <td>-0.323820</td>\n",
       "      <td>-0.188967</td>\n",
       "      <td>-0.067681</td>\n",
       "      <td>-0.326002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1148</th>\n",
       "      <td>-0.391600</td>\n",
       "      <td>-0.161614</td>\n",
       "      <td>0.030336</td>\n",
       "      <td>-0.014560</td>\n",
       "      <td>-0.192436</td>\n",
       "      <td>-0.024372</td>\n",
       "      <td>-0.117045</td>\n",
       "      <td>-0.262193</td>\n",
       "      <td>-0.204994</td>\n",
       "      <td>0.089971</td>\n",
       "      <td>...</td>\n",
       "      <td>0.342659</td>\n",
       "      <td>0.067033</td>\n",
       "      <td>0.147970</td>\n",
       "      <td>0.222644</td>\n",
       "      <td>0.300761</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.193975</td>\n",
       "      <td>0.477112</td>\n",
       "      <td>0.141367</td>\n",
       "      <td>0.377308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1149</th>\n",
       "      <td>-0.463067</td>\n",
       "      <td>-0.048394</td>\n",
       "      <td>-0.320276</td>\n",
       "      <td>0.132649</td>\n",
       "      <td>-0.323820</td>\n",
       "      <td>-0.430543</td>\n",
       "      <td>-0.189671</td>\n",
       "      <td>-0.330710</td>\n",
       "      <td>-0.219213</td>\n",
       "      <td>0.047726</td>\n",
       "      <td>...</td>\n",
       "      <td>0.380707</td>\n",
       "      <td>0.226100</td>\n",
       "      <td>0.398770</td>\n",
       "      <td>0.289582</td>\n",
       "      <td>0.410427</td>\n",
       "      <td>0.193975</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.381073</td>\n",
       "      <td>0.152622</td>\n",
       "      <td>0.485475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1150</th>\n",
       "      <td>-0.270247</td>\n",
       "      <td>-0.252377</td>\n",
       "      <td>-0.130965</td>\n",
       "      <td>0.087322</td>\n",
       "      <td>-0.188967</td>\n",
       "      <td>-0.125836</td>\n",
       "      <td>-0.184207</td>\n",
       "      <td>-0.310081</td>\n",
       "      <td>-0.258113</td>\n",
       "      <td>0.018925</td>\n",
       "      <td>...</td>\n",
       "      <td>0.397713</td>\n",
       "      <td>0.236826</td>\n",
       "      <td>0.190058</td>\n",
       "      <td>0.348684</td>\n",
       "      <td>0.254701</td>\n",
       "      <td>0.477112</td>\n",
       "      <td>0.381073</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.199637</td>\n",
       "      <td>0.440301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1151</th>\n",
       "      <td>-0.089798</td>\n",
       "      <td>-0.275051</td>\n",
       "      <td>-0.137983</td>\n",
       "      <td>-0.325120</td>\n",
       "      <td>-0.067681</td>\n",
       "      <td>-0.125626</td>\n",
       "      <td>-0.269321</td>\n",
       "      <td>-0.153803</td>\n",
       "      <td>-0.166500</td>\n",
       "      <td>-0.394585</td>\n",
       "      <td>...</td>\n",
       "      <td>0.202675</td>\n",
       "      <td>0.321884</td>\n",
       "      <td>0.296698</td>\n",
       "      <td>0.409516</td>\n",
       "      <td>0.200808</td>\n",
       "      <td>0.141367</td>\n",
       "      <td>0.152622</td>\n",
       "      <td>0.199637</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.261412</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1152</th>\n",
       "      <td>-0.711004</td>\n",
       "      <td>-0.113410</td>\n",
       "      <td>-0.435818</td>\n",
       "      <td>-0.004803</td>\n",
       "      <td>-0.326002</td>\n",
       "      <td>-0.471091</td>\n",
       "      <td>-0.351979</td>\n",
       "      <td>-0.483336</td>\n",
       "      <td>-0.547555</td>\n",
       "      <td>0.028440</td>\n",
       "      <td>...</td>\n",
       "      <td>0.672761</td>\n",
       "      <td>0.529515</td>\n",
       "      <td>0.256736</td>\n",
       "      <td>0.747498</td>\n",
       "      <td>0.576465</td>\n",
       "      <td>0.377308</td>\n",
       "      <td>0.485475</td>\n",
       "      <td>0.440301</td>\n",
       "      <td>0.261412</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1153 rows × 1153 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6     \\\n",
       "0     1.000000  0.077693  0.294807 -0.091430  0.337997  0.478794  0.439387   \n",
       "1     0.077693  1.000000  0.126786  0.109063  0.180276 -0.027738  0.191538   \n",
       "2     0.294807  0.126786  1.000000 -0.259657  0.571874  0.317886  0.285163   \n",
       "3    -0.091430  0.109063 -0.259657  1.000000 -0.240268 -0.137877  0.095638   \n",
       "4     0.337997  0.180276  0.571874 -0.240268  1.000000  0.334796  0.281813   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "1148 -0.391600 -0.161614  0.030336 -0.014560 -0.192436 -0.024372 -0.117045   \n",
       "1149 -0.463067 -0.048394 -0.320276  0.132649 -0.323820 -0.430543 -0.189671   \n",
       "1150 -0.270247 -0.252377 -0.130965  0.087322 -0.188967 -0.125836 -0.184207   \n",
       "1151 -0.089798 -0.275051 -0.137983 -0.325120 -0.067681 -0.125626 -0.269321   \n",
       "1152 -0.711004 -0.113410 -0.435818 -0.004803 -0.326002 -0.471091 -0.351979   \n",
       "\n",
       "          7         8         9     ...      1143      1144      1145  \\\n",
       "0     0.491918  0.555327 -0.174763  ... -0.405459 -0.264322 -0.218779   \n",
       "1    -0.096924  0.089351  0.113924  ... -0.318447 -0.258964 -0.186660   \n",
       "2     0.128361  0.156125 -0.221364  ... -0.488042 -0.359850 -0.263919   \n",
       "3     0.063211  0.036920  0.822750  ...  0.100144  0.012187 -0.106914   \n",
       "4     0.119186  0.194218 -0.295784  ... -0.499048 -0.275480 -0.239733   \n",
       "...        ...       ...       ...  ...       ...       ...       ...   \n",
       "1148 -0.262193 -0.204994  0.089971  ...  0.342659  0.067033  0.147970   \n",
       "1149 -0.330710 -0.219213  0.047726  ...  0.380707  0.226100  0.398770   \n",
       "1150 -0.310081 -0.258113  0.018925  ...  0.397713  0.236826  0.190058   \n",
       "1151 -0.153803 -0.166500 -0.394585  ...  0.202675  0.321884  0.296698   \n",
       "1152 -0.483336 -0.547555  0.028440  ...  0.672761  0.529515  0.256736   \n",
       "\n",
       "          1146      1147      1148      1149      1150      1151      1152  \n",
       "0    -0.383507 -0.529830 -0.391600 -0.463067 -0.270247 -0.089798 -0.711004  \n",
       "1    -0.389741 -0.189241 -0.161614 -0.048394 -0.252377 -0.275051 -0.113410  \n",
       "2    -0.434989 -0.440703  0.030336 -0.320276 -0.130965 -0.137983 -0.435818  \n",
       "3    -0.036487 -0.008100 -0.014560  0.132649  0.087322 -0.325120 -0.004803  \n",
       "4    -0.448760 -0.482371 -0.192436 -0.323820 -0.188967 -0.067681 -0.326002  \n",
       "...        ...       ...       ...       ...       ...       ...       ...  \n",
       "1148  0.222644  0.300761  1.000000  0.193975  0.477112  0.141367  0.377308  \n",
       "1149  0.289582  0.410427  0.193975  1.000000  0.381073  0.152622  0.485475  \n",
       "1150  0.348684  0.254701  0.477112  0.381073  1.000000  0.199637  0.440301  \n",
       "1151  0.409516  0.200808  0.141367  0.152622  0.199637  1.000000  0.261412  \n",
       "1152  0.747498  0.576465  0.377308  0.485475  0.440301  0.261412  1.000000  \n",
       "\n",
       "[1153 rows x 1153 columns]"
      ]
     },
     "execution_count": 663,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 664,
   "id": "solved-authority",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02533470842504047"
      ]
     },
     "execution_count": 664,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 665,
   "id": "empty-hello",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.16852567972993246"
      ]
     },
     "execution_count": 665,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mm.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 666,
   "id": "listed-superior",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1153 entries, 0 to 1152\n",
      "Columns: 1153 entries, 0 to 1152\n",
      "dtypes: float64(1153)\n",
      "memory usage: 10.1 MB\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 667,
   "id": "tropical-approach",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>1143</th>\n",
       "      <th>1144</th>\n",
       "      <th>1145</th>\n",
       "      <th>1146</th>\n",
       "      <th>1147</th>\n",
       "      <th>1148</th>\n",
       "      <th>1149</th>\n",
       "      <th>1150</th>\n",
       "      <th>1151</th>\n",
       "      <th>1152</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "      <td>1153.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.188967</td>\n",
       "      <td>0.167672</td>\n",
       "      <td>0.198250</td>\n",
       "      <td>0.147152</td>\n",
       "      <td>0.198236</td>\n",
       "      <td>0.183212</td>\n",
       "      <td>0.191211</td>\n",
       "      <td>0.162377</td>\n",
       "      <td>0.192936</td>\n",
       "      <td>0.156746</td>\n",
       "      <td>...</td>\n",
       "      <td>0.249283</td>\n",
       "      <td>0.206294</td>\n",
       "      <td>0.200140</td>\n",
       "      <td>0.249475</td>\n",
       "      <td>0.223003</td>\n",
       "      <td>0.153837</td>\n",
       "      <td>0.169189</td>\n",
       "      <td>0.172312</td>\n",
       "      <td>0.188761</td>\n",
       "      <td>0.233626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.135027</td>\n",
       "      <td>0.122527</td>\n",
       "      <td>0.137160</td>\n",
       "      <td>0.116219</td>\n",
       "      <td>0.132386</td>\n",
       "      <td>0.127346</td>\n",
       "      <td>0.134698</td>\n",
       "      <td>0.117164</td>\n",
       "      <td>0.135404</td>\n",
       "      <td>0.122655</td>\n",
       "      <td>...</td>\n",
       "      <td>0.191362</td>\n",
       "      <td>0.154472</td>\n",
       "      <td>0.146819</td>\n",
       "      <td>0.185663</td>\n",
       "      <td>0.160420</td>\n",
       "      <td>0.115647</td>\n",
       "      <td>0.123901</td>\n",
       "      <td>0.125737</td>\n",
       "      <td>0.138471</td>\n",
       "      <td>0.173185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000273</td>\n",
       "      <td>0.000081</td>\n",
       "      <td>0.000272</td>\n",
       "      <td>0.000400</td>\n",
       "      <td>0.000172</td>\n",
       "      <td>0.000422</td>\n",
       "      <td>0.000099</td>\n",
       "      <td>0.000305</td>\n",
       "      <td>0.000418</td>\n",
       "      <td>0.000425</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000071</td>\n",
       "      <td>0.000293</td>\n",
       "      <td>0.000271</td>\n",
       "      <td>0.000029</td>\n",
       "      <td>0.000058</td>\n",
       "      <td>0.000035</td>\n",
       "      <td>0.000050</td>\n",
       "      <td>0.000036</td>\n",
       "      <td>0.000406</td>\n",
       "      <td>0.000080</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.082461</td>\n",
       "      <td>0.069386</td>\n",
       "      <td>0.091952</td>\n",
       "      <td>0.060314</td>\n",
       "      <td>0.092758</td>\n",
       "      <td>0.079520</td>\n",
       "      <td>0.084341</td>\n",
       "      <td>0.070132</td>\n",
       "      <td>0.084993</td>\n",
       "      <td>0.060406</td>\n",
       "      <td>...</td>\n",
       "      <td>0.091496</td>\n",
       "      <td>0.077671</td>\n",
       "      <td>0.084687</td>\n",
       "      <td>0.096343</td>\n",
       "      <td>0.091582</td>\n",
       "      <td>0.061554</td>\n",
       "      <td>0.070127</td>\n",
       "      <td>0.070777</td>\n",
       "      <td>0.079756</td>\n",
       "      <td>0.088990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.166569</td>\n",
       "      <td>0.143721</td>\n",
       "      <td>0.176167</td>\n",
       "      <td>0.123448</td>\n",
       "      <td>0.180850</td>\n",
       "      <td>0.165209</td>\n",
       "      <td>0.169426</td>\n",
       "      <td>0.140924</td>\n",
       "      <td>0.171363</td>\n",
       "      <td>0.133400</td>\n",
       "      <td>...</td>\n",
       "      <td>0.200498</td>\n",
       "      <td>0.176967</td>\n",
       "      <td>0.173905</td>\n",
       "      <td>0.213004</td>\n",
       "      <td>0.192232</td>\n",
       "      <td>0.132176</td>\n",
       "      <td>0.148044</td>\n",
       "      <td>0.152791</td>\n",
       "      <td>0.163155</td>\n",
       "      <td>0.194748</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.270364</td>\n",
       "      <td>0.247607</td>\n",
       "      <td>0.284682</td>\n",
       "      <td>0.210116</td>\n",
       "      <td>0.283888</td>\n",
       "      <td>0.265274</td>\n",
       "      <td>0.285054</td>\n",
       "      <td>0.236208</td>\n",
       "      <td>0.272821</td>\n",
       "      <td>0.221861</td>\n",
       "      <td>...</td>\n",
       "      <td>0.378913</td>\n",
       "      <td>0.302754</td>\n",
       "      <td>0.287676</td>\n",
       "      <td>0.363349</td>\n",
       "      <td>0.334381</td>\n",
       "      <td>0.229449</td>\n",
       "      <td>0.245888</td>\n",
       "      <td>0.251420</td>\n",
       "      <td>0.270819</td>\n",
       "      <td>0.344347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 1153 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              0            1            2            3            4     \\\n",
       "count  1153.000000  1153.000000  1153.000000  1153.000000  1153.000000   \n",
       "mean      0.188967     0.167672     0.198250     0.147152     0.198236   \n",
       "std       0.135027     0.122527     0.137160     0.116219     0.132386   \n",
       "min       0.000273     0.000081     0.000272     0.000400     0.000172   \n",
       "25%       0.082461     0.069386     0.091952     0.060314     0.092758   \n",
       "50%       0.166569     0.143721     0.176167     0.123448     0.180850   \n",
       "75%       0.270364     0.247607     0.284682     0.210116     0.283888   \n",
       "max       1.000000     1.000000     1.000000     1.000000     1.000000   \n",
       "\n",
       "              5            6            7            8            9     ...  \\\n",
       "count  1153.000000  1153.000000  1153.000000  1153.000000  1153.000000  ...   \n",
       "mean      0.183212     0.191211     0.162377     0.192936     0.156746  ...   \n",
       "std       0.127346     0.134698     0.117164     0.135404     0.122655  ...   \n",
       "min       0.000422     0.000099     0.000305     0.000418     0.000425  ...   \n",
       "25%       0.079520     0.084341     0.070132     0.084993     0.060406  ...   \n",
       "50%       0.165209     0.169426     0.140924     0.171363     0.133400  ...   \n",
       "75%       0.265274     0.285054     0.236208     0.272821     0.221861  ...   \n",
       "max       1.000000     1.000000     1.000000     1.000000     1.000000  ...   \n",
       "\n",
       "              1143         1144         1145         1146         1147  \\\n",
       "count  1153.000000  1153.000000  1153.000000  1153.000000  1153.000000   \n",
       "mean      0.249283     0.206294     0.200140     0.249475     0.223003   \n",
       "std       0.191362     0.154472     0.146819     0.185663     0.160420   \n",
       "min       0.000071     0.000293     0.000271     0.000029     0.000058   \n",
       "25%       0.091496     0.077671     0.084687     0.096343     0.091582   \n",
       "50%       0.200498     0.176967     0.173905     0.213004     0.192232   \n",
       "75%       0.378913     0.302754     0.287676     0.363349     0.334381   \n",
       "max       1.000000     1.000000     1.000000     1.000000     1.000000   \n",
       "\n",
       "              1148         1149         1150         1151         1152  \n",
       "count  1153.000000  1153.000000  1153.000000  1153.000000  1153.000000  \n",
       "mean      0.153837     0.169189     0.172312     0.188761     0.233626  \n",
       "std       0.115647     0.123901     0.125737     0.138471     0.173185  \n",
       "min       0.000035     0.000050     0.000036     0.000406     0.000080  \n",
       "25%       0.061554     0.070127     0.070777     0.079756     0.088990  \n",
       "50%       0.132176     0.148044     0.152791     0.163155     0.194748  \n",
       "75%       0.229449     0.245888     0.251420     0.270819     0.344347  \n",
       "max       1.000000     1.000000     1.000000     1.000000     1.000000  \n",
       "\n",
       "[8 rows x 1153 columns]"
      ]
     },
     "execution_count": 667,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "metric-allen",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
